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

align scaladoc with examples from the official docs for IO.shift - fixes #559 #567

Merged
merged 4 commits into from
Jun 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 41 additions & 11 deletions core/shared/src/main/scala/cats/effect/IO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -862,17 +862,51 @@ private[effect] abstract class IOInstances extends IOLowPriorityInstances {
}

/**
* @define shiftDesc For example we can introduce an asynchronous
* @define shiftDesc Note there are 2 overloads of the `IO.shift` function:
*
* - One that takes a `ContextShift` that manages the
* thread-pool used to trigger async boundaries.
* - Another that takes a Scala `ExecutionContext` as the
* thread-pool.
*
* Please use the former by default and use the latter
* only for fine-grained control over the thread pool in
* use.
*
* By default, Cats Effect can provide instance of
* `ContextShift[IO]` that manages thread-pools, but
* only if there’s an `ExecutionContext` in scope or
* if `IOApp` is used:
*
* {{{
* import cats.effect.{IO, ContextShift}
*
* val ec = ExecutionContext.fromExecutor(Executors.newFixedThreadPool(...))
* val contextShift = IO.contextShift(ec)
* }}}
*
* For example we can introduce an asynchronous
* boundary in the `flatMap` chain before a certain task:
* {{{
* val task = IO(println("task"))
*
* IO.shift(contextShift).flatMap(_ => task)
* }}}
*
* Note that the ContextShift value is taken implicitly
* from the context so you can just do this:
*
* {{{
* IO.shift.flatMap(_ => task)
* }}}
*
* Or using Cats syntax:
* {{{
* import cats.syntax.all._
* import cats.syntax.apply._
*
* IO.shift *> task
* // equivalent to
* ContextShift[IO].shift *> task
* }}}
*
* Or we can specify an asynchronous boundary ''after'' the
Expand All @@ -884,6 +918,8 @@ private[effect] abstract class IOInstances extends IOLowPriorityInstances {
* Or using Cats syntax:
* {{{
* task <* IO.shift
* // equivalent to
* task <* ContextShift[IO].shift
* }}}
*
* Example of where this might be useful:
Expand Down Expand Up @@ -951,13 +987,13 @@ private[effect] abstract class IOInstances extends IOLowPriorityInstances {
* - preventing an overflow of the call stack in the case of
* improperly constructed `async` actions
*
* Note there are 2 overloads of this function:
* Note there are 2 overloads of this function:
*
* - one that takes an [[Timer]] ([[IO.shift(implicit* link]])
* - one that takes a Scala `ExecutionContext` ([[IO.shift(ec* link]])
*
* Use the former by default, use the later for fine grained
* control over the thread pool used.
* Use the former by default, use the later for fine grained
* control over the thread pool used.
*/
object IO extends IOInstances {

Expand Down Expand Up @@ -1227,9 +1263,6 @@ object IO extends IOInstances {
* Asynchronous boundary described as an effectful `IO`, managed
* by the provided [[ContextShift]].
*
* This operation can be used in `flatMap` chains to "shift" the
* continuation of the run-loop to another thread or call stack.
*
* $shiftDesc
*
* @param cs is the [[ContextShift]] that's managing the thread-pool
Expand All @@ -1242,9 +1275,6 @@ object IO extends IOInstances {
* Asynchronous boundary described as an effectful `IO`, managed
* by the provided Scala `ExecutionContext`.
*
* This operation can be used in `flatMap` chains to "shift" the
* continuation of the run-loop to another thread or call stack.
*
* $shiftDesc
*
* @param ec is the Scala `ExecutionContext` that's managing the
Expand Down