Skip to content

Commit bbdb6b5

Browse files
authored
Merge pull request #1740 from michael-smith/1474
Removed incorrect text from guide.md docs regarding interruption of u…
2 parents 9e75e81 + 2d72914 commit bbdb6b5

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

site/docs/guide.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ program.compile.drain.unsafeRunSync
449449

450450
Let's take this line by line now, so we can understand what's going on.
451451
```scala
452-
val program =
452+
val program =
453453
Stream.eval(Deferred[IO, Unit]).flatMap { switch =>
454454
```
455455

@@ -462,7 +462,7 @@ val switcher =
462462

463463
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.
464464
```scala
465-
val program =
465+
val program =
466466
Stream.repeatEval(IO(println(java.time.LocalTime.now))).metered(1.second)
467467
```
468468

@@ -478,7 +478,7 @@ In this line we call `interruptWhen` on the stream, obtaining a stream that will
478478

479479
This is a way to create a program that runs for a given time, in this example 5 seconds. Timed interruption is such a common use case that FS2 defines the `interruptAfter` method. Armed with this knowledge we can rewrite our example as:
480480
```scala mdoc
481-
val program1 =
481+
val program1 =
482482
Stream.
483483
repeatEval(IO(println(java.time.LocalTime.now))).
484484
metered(1.second).
@@ -670,7 +670,7 @@ In FS2, a stream can terminate in one of three ways:
670670
Regarding 3:
671671

672672
* 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 if FS2 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.
674674
* _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 `++` for this purpose._
675675

676676
Let's look at some examples of how this plays out, starting with the synchronous interruption case:

0 commit comments

Comments
 (0)