问题标签 [zio]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
279 浏览

scala - 期货/并行代码的有用堆栈跟踪

在线程中运行代码时,堆栈跟踪通常不显示代码在哪里组装/定义的逻辑流,而是显示执行堆栈跟踪。这通常不是我调试和上下文所需的信息。

ZIO 在提供有关问题所在和位置的背景方面做得很好。

但是,如果您有一个不太可能移植到 zio 的遗留项目,我怎样才能获得类似的异常/上下文信息而不必重写我所有的期货和单子?

0 投票
1 回答
156 浏览

scala - 是否可以将 GraphQLRequest 用于 Caliban 中的客户端?

我想测试我的 Caliban Http4s Web 服务。

Http4sAdapter它用于GraphQLRequest对请求正文进行建模。

所以我认为在客户端我也可以使用它。

一个简单的请求有效:

但是如果我使用变量它不会:

它只是挂起 - 甚至没有例外。

我尝试使用0.4.2and 0.5.0

我添加了一个要点来显示客户端代码。它使用CirceSttp客户端要点

0 投票
2 回答
286 浏览

scala - 如何扩展 ZIO 测试的 TestEnvironment

我想测试以下功能:

如果环境只使用标准 ZIO 环境,例如Console with Clock,则测试将开箱即用:

测试环境将由zio-test.

所以问题是,如何用我的Loggings模块扩展 TestEnvironment?

0 投票
1 回答
450 浏览

scala - 将 ZIO ZStreams 列表合并为一个

我的旧代码支持使用 SqsStream 使用一个 SQS 队列。我必须更新它以支持给定队列 URL 列表的多个队列。

方法内容:

但是编译器抱怨,因为它需要一个(ZIO,ZIO,ZIO),而我给了它一个(ZIO,ZIO,List)。我假设我必须将该列表中的所有效果减少为将handleMessage在所有队列中并行执行的单个效果,但我不确定语法,因为我没有使用 ZIO 的经验。

基本上到了这一点,

我的网址变成了 ZStream。我想我需要ZStream.flatMapPar使用这个元素和下一个元素来调用,依此类推,直到它们都被压平在一起。我该怎么做?

0 投票
1 回答
75 浏览

scala - TMap 在 ZIO RC18-2 上无法正常工作

我尝试使用TMap以下方式:

定义TMap

输入一个条目:

然后尝试获取该值:

正如评论所暗示的,当我请求条目时,新值不存在。

我错过了什么吗?

0 投票
1 回答
436 浏览

scala - How to correctly verify scheduled invocations in ZIO Test

I am new to ZIO and ZIO Test and I'd like to test a scheduling service I wrote under ZIO v1.0.0RC17:

The service(s):

The service of ModuleA should basically run the Service method of ModuleB once a day with the argument fed into ModuleA.Service.run.

The test I'd like to write:

I simplified the test using a counter, in reality I'd like to use mockito to verify the invocation count as well as the correct argument. However, this test does not work. In my understanding this is because of a race condition introduced by a timing overhead as described in https://zio.dev/docs/howto/howto_test_effects#testing-clock.

Now, there are examples of how to tackle this problem by using a Promise. I tried that by replacing the counter with a promise like so:

Using this, the test won't terminate. However, I am pretty sure I am using the promise wrongly.

How would one approach this test scenario correctly?

0 投票
1 回答
150 浏览

scala - 如何同时发出 10 个 http 请求?

我有 10 个请求

如何同时发送这些请求?

我试过

但这给了我各种有趣的编译错误。

0 投票
1 回答
489 浏览

scala - Why putStrLn of zio didn't output

Why putStrLn in flatMap followed by a result statement didn't get effectively write to stdout?

0 投票
2 回答
1125 浏览

scala - 使用 ZIO 在 Scala 中组合多个期货和期权

我刚刚开始评估 ZIO 以改进我的异步 Scala 代码的编程模型和性能。在我的代码库中,我Future[Option[T]]经常处理,到目前为止,我已经使用 Scalaz 的OptionTmonad 转换器处理了这个问题。现在我想用 ZIO 试试这个。

考虑两个函数:

def foo: String => Future[Option[T]]def bar: T => Future[U]

我试过这样的事情:

根据我的 IDE,在这种情况下t属于类型。ZIO[Any, Any, String]我不知道该怎么办。

我想考虑三种可能性:

  • foo产生一个Some可以与值上的其他函数组合的“成功”案例
  • foo产生一个的情况None
  • 任一函数产生错误的情况

我不确定如何使用 ZIO 在这种情况下解析这些可能性。任何帮助表示赞赏。

0 投票
1 回答
935 浏览

scala - ZIO Test 中的“测试正在使用时间,但没有提前测试时钟”

将我的测试迁移到 RC18 后,我收到以下警告并且测试挂起:

我有以下测试:

我怀疑我创建了错误的图层,因为这是我为迁移所做的唯一更改。

文档中的标准测试也失败了(时间为 0):

当我定义图层时:

val testLayer: ZLayer[Live, Nothing, Loggings with Blocking with Clock] = (Console.live >>> loggings.consoleLogger) ++ Blocking.live ++ Clock.live

时间完全没有调整。

这是我要测试的代码:

所以我想快进ZIO.sleep(3.seconds)