@@ -10,12 +10,12 @@ import scala.util.Random
10
10
object Fibers extends IOApp .Simple {
11
11
12
12
val sequentialOps =
13
- IO (" Step1" ).debug >> IO (" Step2" ).debug >> IO (" Step3" ).debug
13
+ IO (" Step1" ).printIO >> IO (" Step2" ).printIO >> IO (" Step3" ).printIO
14
14
15
15
val io : IO [String ] =
16
- IO (" Starting a task" ).debug >> IO .sleep(400 .millis) >> IO (
16
+ IO (" Starting a task" ).printIO >> IO .sleep(400 .millis) >> IO (
17
17
" Task completed"
18
- ).debug
18
+ ).printIO
19
19
20
20
val fibExec = for {
21
21
fib <- io.start
@@ -24,39 +24,39 @@ object Fibers extends IOApp.Simple {
24
24
25
25
val fibCancel : IO [Outcome [IO , Throwable , String ]] = for {
26
26
fib <- io.start
27
- _ <- IO .sleep(100 .millis) >> fib.cancel >> IO (" Fiber cancelled" ).debug
27
+ _ <- IO .sleep(100 .millis) >> fib.cancel >> IO (" Fiber cancelled" ).printIO
28
28
res <- fib.join
29
29
} yield res
30
30
31
31
val outcome : IO [String ] = fibCancel.flatMap {
32
- case Outcome .Succeeded (fa) => IO (" fiber executed successfully" ).debug
33
- case Outcome .Errored (e) => IO (" error occurred during fiber execution" ).debug
34
- case Outcome .Canceled () => IO (" fiber was canceled!" ).debug
32
+ case Outcome .Succeeded (fa) => IO (" fiber executed successfully" ).printIO
33
+ case Outcome .Errored (e) => IO (" error occurred during fiber execution" ).printIO
34
+ case Outcome .Canceled () => IO (" fiber was canceled!" ).printIO
35
35
}
36
36
37
37
val ioWithCancelationHook =
38
- io.onCancel(IO (" Applying cancelation finalizer" ).debug .void)
38
+ io.onCancel(IO (" Applying cancelation finalizer" ).printIO .void)
39
39
val finaliserAction = for {
40
40
fib <- ioWithCancelationHook.start
41
- _ <- IO .sleep(100 .millis) >> fib.cancel >> IO (" fiber cancelled" ).debug
41
+ _ <- IO .sleep(100 .millis) >> fib.cancel >> IO (" fiber cancelled" ).printIO
42
42
_ <- fib.join
43
43
} yield ()
44
44
45
45
val participant1 =
46
- IO (" Start Task1" ).debug >> IO .sleep(Random .nextInt(1000 ).millis) >> IO (
46
+ IO (" Start Task1" ).printIO >> IO .sleep(Random .nextInt(1000 ).millis) >> IO (
47
47
" Task 1 completed"
48
- ).debug
48
+ ).printIO
49
49
val participant2 =
50
- IO (" Start Task2" ).debug >> IO .sleep(Random .nextInt(1000 ).millis) >> IO (
50
+ IO (" Start Task2" ).printIO >> IO .sleep(Random .nextInt(1000 ).millis) >> IO (
51
51
" Task 2 completed"
52
- ).debug
52
+ ).printIO
53
53
val raceResult : IO [Either [String , String ]] =
54
54
IO .race(participant1, participant2)
55
55
56
56
val participant1WithFinaliser =
57
- participant1.onCancel(IO (" Task 1 got canceled" ).debug .void)
57
+ participant1.onCancel(IO (" Task 1 got canceled" ).printIO .void)
58
58
val participant2WithFinaliser =
59
- participant2.onCancel(IO (" Task 2 got canceled" ).debug .void)
59
+ participant2.onCancel(IO (" Task 2 got canceled" ).printIO .void)
60
60
val raceWithFinaliser =
61
61
IO .race(participant1WithFinaliser, participant2WithFinaliser)
62
62
@@ -67,7 +67,7 @@ object Fibers extends IOApp.Simple {
67
67
68
68
val ioWithTimeout : IO [String ] = participant1.timeout(400 .millis)
69
69
70
- val ioWithFallback = participant1.timeoutTo(400 .millis, IO (" Fallback IO executed after timeout" ).debug )
70
+ val ioWithFallback = participant1.timeoutTo(400 .millis, IO (" Fallback IO executed after timeout" ).printIO )
71
71
72
72
override def run : IO [Unit ] = ioWithFallback.void
73
73
}
0 commit comments