Scala 我如何使用;writeOutputStream“;使用fs2流[IO,字节]

Scala 我如何使用;writeOutputStream“;使用fs2流[IO,字节],scala,aws-lambda,fs2,Scala,Aws Lambda,Fs2,我正在尝试使用输出到JavaAWS lambda fn。我不知道如何提供它正在寻找的隐式参数: “找不到参数cs:ContextShift[IO]的隐式表达式” 我找到了一些方法来创建我自己的隐式ContextShift对象,但对于我正在尝试做的事情来说,这似乎有些过头了 final def handleRequest(in: InputStream, out: OutputStream, context: Context): Unit = (for { bytes <- in.com

我正在尝试使用输出到JavaAWS lambda fn。我不知道如何提供它正在寻找的隐式参数:

“找不到参数cs:ContextShift[IO]的隐式表达式”

我找到了一些方法来创建我自己的隐式ContextShift对象,但对于我正在尝试做的事情来说,这似乎有些过头了

final def handleRequest(in: InputStream, out: OutputStream, context: Context): Unit = (for {
  bytes <- in.compile.toList
  str   =  getString(bytes)
  args  <- decode(str).raiseIO
  _     <- produce(args).to(writeOutputStream(IO(out), global)).compile.drain
} yield Unit).unsafeRunAsyncAndForget() // throws exception in the case of Failure
// ------------------------------------------------
// produce(args: MyCaseClass): fs2.Stream[IO, Byte]
final def handleRequest(in:InputStream,out:OutputStream,context:context):单位=(用于{
字节
“默认情况下,Cats Effect可以提供管理线程池的ContextShift[IO]实例,但仅当作用域中存在ExecutionContext或使用了IOApp时。”

--猫效应

执行上下文中
。 使用
IOApp
。 谢谢!“IO.contextShift(全球)”正是我所需要的。
import cats.effect.{IO, ContextShift}
import scala.concurrent.ExecutionContext.Implicits.global

val contextShift = IO.contextShift(global)
import cats.effect.{IO, IOApp, ContextShift}

object Main extends IOApp {
  override def run(args: List[String]): IO[ExitCode] = {
     val cs = implicitly[ContextShift[IO]]
  }
}