Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a section on `interruptWhen` to guide.md #1644

Merged
merged 2 commits into from Oct 8, 2019

Conversation

@poliez
Copy link
Contributor

commented Sep 30, 2019

No description provided.

Copy link
Member

left a comment

Great example, very clear!

### Interruption

Sometimes some tasks have to run only when some conditions are met or until some other task completes. Luckily for us, `Stream` defines some really useful methods that let us accomplish this.
In the following example we will see how `interruptWhen` helps us to describe such cases. we will describe a program composed by two concurrent streams: the first will print the current time to the console every second, the second will stop the first.

This comment has been minimized.

Copy link
@mpilquist

mpilquist Oct 4, 2019

Member

s/we/We/

Stream.eval(Deferred[IO, Unit]).flatMap { switch =>
```

Here we create a `Stream[IO, Deferred[IO, Unit]]`. [`Deferred`](https://typelevel.org/cats-effect/concurrency/deferred.html) is a concurrency primitive that represents an unset promise. we will use the emitted istance of `Deferred[IO, Unit]` as a mechanism to signal the completion of a task. Given this purpose, we call this instance `switch`.

This comment has been minimized.

Copy link
@mpilquist

mpilquist Oct 4, 2019

Member

s/we/We/

This comment has been minimized.

Copy link
@SystemFw

SystemFw Oct 4, 2019

Member

I would only change "unset promise" to "a condition yet to be fulfilled" possibly

Copy link
Member

left a comment

Nice :)

@poliez

This comment has been minimized.

Copy link
Contributor Author

commented Oct 6, 2019

Thanks to both of you! I'll commit the requested changes in a few minutes. Thanks for accepting this, I'm happy to help 😄

@SystemFw SystemFw merged commit 5eb3d9d into functional-streams-for-scala:master Oct 8, 2019
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.