Skip to content

Instantly share code, notes, and snippets.

@qingwei91
Created December 20, 2019 14:28
Show Gist options
  • Select an option

  • Save qingwei91/b55ead4dc758ac447739eb60551a8c76 to your computer and use it in GitHub Desktop.

Select an option

Save qingwei91/b55ead4dc758ac447739eb60551a8c76 to your computer and use it in GitHub Desktop.
import cats.effect._
import scala.concurrent.ExecutionContext.global
// needed to perform logical fork
implicit val cs = IO.contextShift(global)
// an infinite `flatMap` chain as the innerIO always return None
val myIO = retryIfNone(IO(None))
// perform a logical fork using `.start`, this to allow cancellation
val fiber: Fiber[IO, Int] = myIO.start.unsafeRunSync
// cancel the forked fiber
fiber.cancel.unsafeRunSync
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment