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

Introduced Suspendable type class #710

Merged
merged 3 commits into from
Aug 16, 2016

Conversation

mpilquist
Copy link
Member

This PR moves suspend and delay from the Effect type class to a
new Suspendable type class. There are two motivations for doing this:

  • Exposing unsafeRunAsync to any function that requires suspend
    or delay gives up a lot of parametricity.
  • Some type constructors have Suspendable instances but do not
    support value extraction. This came up in the port of Doobie to
    FS2
    .

This came up on Gitter a while back as
well
.

/cc @tpolecat @guersam

This PR moves `suspend` and `delay` from the `Effect` type class to a
new `Suspendable` type class. There are two motivations for doing this:

 - Exposing `unsafeRunAsync` to any function that requires `suspend`
   or `delay` gives up a lot of parametricity.

 - Some type constructors have `Suspendable` instances but do not
   support value extraction. This came up in the [port of Doobie to
   FS2](typelevel/doobie#323 (comment)).

This [came up on Gitter a while back as
well](http://www.gitterforum.com/discussion/scalaz-scalaz-stream?page=143).
@@ -108,14 +108,15 @@ val eff = Stream.eval(Task.delay { println("TASK BEING RUN!!"); 1 + 1 })

[`Task`](../core/shared/src/main/scala/fs2/Task.scala) is an effect type we'll see a lot in these examples. Creating a `Task` has no side effects, and `Stream.eval` doesn't do anything at the time of creation, it's just a description of what needs to happen when the stream is eventually interpreted. Notice the type of `eff` is now `Stream[Task,Int]`.

The `eval` function works for any effect type, not just `Task`. FS2 does not care what effect type you use for your streams. You may use the included [`Task` type][Task] for effects or bring your own, just by implementing a few interfaces for your effect type ([`Catchable`][Catchable] and optionally [`Effect`][Effect] or [`Async`][Async] if you wish to use various concurrent operations discussed later). Here's the signature of `eval`:
The `eval` function works for any effect type, not just `Task`. FS2 does not care what effect type you use for your streams. You may use the included [`Task` type][Task] for effects or bring your own, just by implementing a few interfaces for your effect type ([`Catchable`][Catchable], [`Suspendable`][Suspendable], [`Effect`][Effect], and optional [`Async`][Async] if you wish to use various concurrent operations discussed later). Here's the signature of `eval`:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"optionally Async", not "optional Async"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed

@tpolecat
Copy link
Member

👍

@pchiusano
Copy link
Contributor

lgtm

@guersam
Copy link
Contributor

guersam commented Aug 16, 2016

👍

@mpilquist mpilquist merged commit eefc080 into typelevel:series/0.9 Aug 16, 2016
@mpilquist mpilquist mentioned this pull request Aug 22, 2016
@mpilquist mpilquist deleted the topic/suspendable branch February 18, 2020 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants