Created
December 20, 2019 14:28
-
-
Save qingwei91/b55ead4dc758ac447739eb60551a8c76 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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