August 2018
Intermediate to advanced
380 pages
10h 2m
English
Suppose we have one range shorter than another, and we would like to cancel the longer range computation when the first one is completed. You can do this with Fibers as follows:
def cancelled: IO[Int] = for { f1 <- sum(1 , 5 ).start f2 <- sum(10, 20).start res <- f1.join _ <- f2.cancel } yield res
We can run it as follows:
benchmarkFlush(cancelled).unsafeRunSync
And the result of the execution is as follows:

Notice that the second range gets cancelled once the first range finishes its execution.
In this chapter, we have discussed the currency capabilities of the Cats effects library in detail. It is the primary objective of ...