You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `switcher` will be the stream that, after 5 seconds, will "flip" the `switch` calling `complete` on it. `delayBy` concatenates the stream after another that sleeps for the specified duration, effectively delaying the evaluation of our stream.
@@ -478,7 +478,7 @@ In this line we call `interruptWhen` on the stream, obtaining a stream that will
478
478
479
479
This is a way to create a program that runs for a giventime, in this example 5 seconds. Timed interruption is such a common use case that FS2 defines the `interruptAfter` method. Armedwiththis knowledge we can rewrite our example as:
480
480
```scala mdoc
481
-
valprogram1=
481
+
valprogram1=
482
482
Stream.
483
483
repeatEval(IO(println(java.time.LocalTime.now))).
484
484
metered(1.second).
@@ -670,7 +670,7 @@ In FS2, a stream can terminate in one of three ways:
670
670
Regarding3:
671
671
672
672
*A stream will never be interrupted while it is acquiring a resource (via `bracket`) or while it is releasing a resource. The `bracket` function guarantees that ifFS2 starts acquiring the resource, the corresponding release action will be run.
673
-
*Other than that, Streams can be interrupted in between any two 'steps' of the stream. The steps themselves are atomic from the perspective of FS2. `Stream.eval(eff)` is a single step, `Stream.emit(1)` is a single step, `Stream(1,2,3)` is a single step (emitting a chunk), and all other operations (like `handleErrorWith`, `++`, and `flatMap`) are multiple steps and can be interrupted.But importantly, user-provided effects that are passed to `eval` are never interrupted once they are started (and FS2 does not have enough knowledge of user-provided effects to know how to interrupt them anyway).
673
+
*Other than that, Streams can be interrupted in between any two 'steps' of the stream. The steps themselves are atomic from the perspective of FS2. `Stream.eval(eff)` is a single step, `Stream.emit(1)` is a single step, `Stream(1,2,3)` is a single step (emitting a chunk), and all other operations (like `handleErrorWith`, `++`, and `flatMap`) are multiple steps and can be interrupted.
674
674
* _Always use `bracket` or a `bracket`-based function like `onFinalize` for supplying resource cleanup logic or any other logic you want to be run regardless of how the stream terminates. Don't use `handleErrorWith` or `++` forthis purpose._
675
675
676
676
Let's look at some examples of how this plays out, starting with the synchronous interruption case:
0 commit comments