如何将 "writeOutputStream" 与 fs2 Stream[IO, Byte] 一起使用

How do I use "writeOutputStream" with an fs2 Stream[IO, Byte]

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

"no implicits found for parameter cs: ContextShift[IO]"

我发现了一些 documentation 用于创建我自己的隐式 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]

"By default, Cats Effect can provide instance of ContextShift[IO] that manages thread-pools, but only if there’s an ExecutionContext in scope or if IOApp is used."

-- 猫效应 documentation.

来自 ExecutionContext.

import cats.effect.{IO, ContextShift}
import scala.concurrent.ExecutionContext.Implicits.global

val contextShift = IO.contextShift(global)

使用 IOApp.

import cats.effect.{IO, IOApp, ContextShift}

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