Packages

trait Concurrent[F[_]] extends Async[F]

Type class for Async data types that are cancelable and can be started concurrently.

Thus this type class allows abstracting over data types that:

  1. implement the Async algebra, with all its restrictions
  2. can provide logic for cancellation, to be used in race conditions in order to release resources early (in its cancelable builder)

Due to these restrictions, this type class also affords to describe a start operation that can start async processes, suspended in the context of F[_] and that can be canceled or joined.

Without cancellation being baked in, we couldn't afford to do it. See below.

Cancelable builder

The signature exposed by the cancelable builder is this:

(Either[Throwable, A] => Unit) => CancelToken[F]

CancelToken[F] is just an alias for F[Unit] and used to represent a cancellation action which will send a signal to the producer, that may observe it and cancel the asynchronous process.

On Cancellation

Simple asynchronous processes, like Scala's Future, can be described with this very basic and side-effectful type and you should recognize what is more or less the signature of Future#onComplete or of Async.async (minus the error handling):

(A => Unit) => Unit

But many times the abstractions built to deal with asynchronous tasks can also provide a way to cancel such processes, to be used in race conditions in order to cleanup resources early, so a very basic and side-effectful definition of asynchronous processes that can be canceled would be:

(A => Unit) => CancelToken

This is approximately the signature of JavaScript's setTimeout, which will return a "task ID" that can be used to cancel it. Or of Java's ScheduledExecutorService#schedule, which will return a Java ScheduledFuture that has a .cancel() operation on it.

Similarly, for Concurrent data types, we can provide cancellation logic that can be triggered in race conditions to cancel the on-going processing, only that Concurrent's cancelation token is an action suspended in an F[Unit].

Suppose you want to describe a "sleep" operation, like that described by Timer to mirror Java's ScheduledExecutorService.schedule or JavaScript's setTimeout:

def sleep(d: FiniteDuration): F[Unit]

This signature is in fact incomplete for data types that are not cancelable, because such equivalent operations always return some cancellation token that can be used to trigger a forceful interruption of the timer. This is not a normal "dispose" or "finally" clause in a try/catch block, because "cancel" in the context of an asynchronous process is concurrent with the task's own run-loop.

To understand what this means, consider that in the case of our sleep as described above, on cancellation we'd need a way to signal to the underlying ScheduledExecutorService to forcefully remove the scheduled Runnable from its internal queue of scheduled tasks, before its execution. Therefore, without a cancelable data type, a safe signature needs to return a cancellation token, so it would look like this:

def sleep(d: FiniteDuration): F[(F[Unit], F[Unit])]

This function is returning a tuple, with one F[Unit] to wait for the completion of our sleep and a second F[Unit] to cancel the scheduled computation in case we need it. This is in fact the shape of Fiber's API. And this is exactly what the start operation returns.

The difference between a Concurrent data type and one that is only Async is that you can go from any F[A] to a F[Fiber[F, A]], to participate in race conditions and that can be canceled should the need arise, in order to trigger an early release of allocated resources.

Thus a Concurrent data type can safely participate in race conditions, whereas a data type that is only Async cannot do it without exposing and forcing the user to work with cancellation tokens. An Async data type cannot expose for example a start operation that is safe.

Resource-safety

Concurrent data types are required to cooperate with Bracket. Concurrent being cancelable by law, what this means for the corresponding Bracket is that cancelation can be observed and that in the case of bracketCase the ExitCase.Canceled branch will get executed on cancelation.

By default the cancelable builder is derived from bracketCase and from asyncF, so what this means is that whatever you can express with cancelable, you can also express with bracketCase.

For uncancelable, the cancel signal has no effect on the result of join and the cancelable token returned by ConcurrentEffect.runCancelable on evaluation will have no effect if evaluated.

So uncancelable must undo the cancellation mechanism of cancelable, with this equivalence:

F.uncancelable(F.cancelable { cb => f(cb); token }) <-> F.async(f)

Sample:

val F = Concurrent[IO]
val timer = Timer[IO]

// Normally Timer#sleep yields cancelable tasks
val tick = F.uncancelable(timer.sleep(10.seconds))

// This prints "Tick!" after 10 seconds, even if we are
// canceling the Fiber after start:
for {
  fiber <- F.start(tick)
  _ <- fiber.cancel
  _ <- fiber.join
  _ <- F.delay { println("Tick!") }
} yield ()

When doing bracket or bracketCase, acquire and release operations are guaranteed to be uncancelable as well.

Annotations
@implicitNotFound()
Source
Concurrent.scala
Linear Supertypes
Async[F], LiftIO[F], Sync[F], Defer[F], Bracket[F, Throwable], MonadError[F, Throwable], Monad[F], FlatMap[F], ApplicativeError[F, Throwable], Applicative[F], InvariantMonoidal[F], Apply[F], ApplyArityFunctions[F], InvariantSemigroupal[F], Semigroupal[F], Functor[F], Invariant[F], Serializable, AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Concurrent
  2. Async
  3. LiftIO
  4. Sync
  5. Defer
  6. Bracket
  7. MonadError
  8. Monad
  9. FlatMap
  10. ApplicativeError
  11. Applicative
  12. InvariantMonoidal
  13. Apply
  14. ApplyArityFunctions
  15. InvariantSemigroupal
  16. Semigroupal
  17. Functor
  18. Invariant
  19. Serializable
  20. AnyRef
  21. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Abstract Value Members

  1. abstract def async[A](k: ((Either[Throwable, A]) => Unit) => Unit): F[A]

    Creates a simple, non-cancelable F[A] instance that executes an asynchronous process on evaluation.

    Creates a simple, non-cancelable F[A] instance that executes an asynchronous process on evaluation.

    The given function is being injected with a side-effectful callback for signaling the final result of an asynchronous process.

    This operation could be derived from asyncF, because:

    F.async(k) <-> F.asyncF(cb => F.delay(k(cb)))

    As an example of wrapping an impure async API, here's the implementation of Async.shift:

    def shift[F[_]](ec: ExecutionContext)(implicit F: Async[F]): F[Unit] =
      F.async { cb =>
        // Scheduling an async boundary (logical thread fork)
        ec.execute(new Runnable {
          def run(): Unit = {
            // Signaling successful completion
            cb(Right(()))
          }
        })
      }
    k

    is a function that should be called with a callback for signaling the result once it is ready

    Definition Classes
    Async
    See also

    asyncF for the variant that can suspend side effects in the provided registration function.

  2. abstract def asyncF[A](k: ((Either[Throwable, A]) => Unit) => F[Unit]): F[A]

    Creates a simple, non-cancelable F[A] instance that executes an asynchronous process on evaluation.

    Creates a simple, non-cancelable F[A] instance that executes an asynchronous process on evaluation.

    The given function is being injected with a side-effectful callback for signaling the final result of an asynchronous process. And its returned result needs to be a pure F[Unit] that gets evaluated by the runtime.

    Note the simpler async variant async can be derived like this:

    F.async(k) <-> F.asyncF(cb => F.delay(k(cb)))

    For wrapping impure APIs usually you can use the simpler async, however asyncF is useful in cases where impure APIs are wrapped with the help of pure abstractions, such as Ref.

    For example here's how a simple, "pure Promise" implementation could be implemented via Ref (sample is for didactic purposes, as you have a far better Deferred available):

    import cats.effect.concurrent.Ref
    
    type Callback[-A] = Either[Throwable, A] => Unit
    
    class PurePromise[F[_], A](ref: Ref[F, Either[List[Callback[A]], A]])
      (implicit F: Async[F]) {
    
      def get: F[A] = F.asyncF { cb =>
        ref.modify {
          case current @ Right(result) =>
            (current, F.delay(cb(Right(result))))
          case Left(list) =>
            (Left(cb :: list), F.unit)
        }
      }
    
      def complete(value: A): F[Unit] =
        F.flatten(ref.modify {
          case Left(list) =>
            (Right(value), F.delay(list.foreach(_(Right(value)))))
          case right =>
            (right, F.unit)
        })
    }

    N.B. if F[_] is a cancelable data type (i.e. implementing Concurrent), then the returned F[Unit] can be cancelable, its evaluation hooking into the underlying cancelation mechanism of F[_], so something like this behaves like you'd expect:

    def delayed[F[_], A](thunk: => A)
      (implicit F: Async[F], timer: Timer[F]): F[A] = {
    
      timer.sleep(1.second) *> F.delay(cb(
        try cb(Right(thunk))
        catch { case NonFatal(e) => Left(cb(Left(e))) }
      ))
    }

    The asyncF operation behaves like Sync.suspend, except that the result has to be signaled via the provided callback.

    ERROR HANDLING

    As a matter of contract the returned F[Unit] should not throw errors. If it does, then the behavior is undefined.

    This is because by contract the provided callback should only be called once. Calling it concurrently, multiple times, is a contract violation. And if the returned F[Unit] throws, then the implementation might have called it already, so it would be a contract violation to call it without expensive synchronization.

    In case errors are thrown the behavior is implementation specific. The error might get logged to stderr, or via other mechanisms that are implementations specific.

    k

    is a function that should be called with a callback for signaling the result once it is ready

    Definition Classes
    Async
    See also

    async for the simpler variant.

  3. abstract def bracketCase[A, B](acquire: F[A])(use: (A) => F[B])(release: (A, ExitCase[Throwable]) => F[Unit]): F[B]

    A generalized version of bracket which uses ExitCase to distinguish between different exit cases when releasing the acquired resource.

    A generalized version of bracket which uses ExitCase to distinguish between different exit cases when releasing the acquired resource.

    acquire

    is an action that "acquires" some expensive resource, that needs to be used and then discarded

    use

    is the action that uses the newly allocated resource and that will provide the final result

    release

    is the action that's supposed to release the allocated resource after use is done, by observing and acting on its exit condition. Throwing inside this function leads to undefined behavior since it's left to the implementation.

    Definition Classes
    Bracket
  4. abstract def flatMap[A, B](fa: F[A])(f: (A) => F[B]): F[B]
    Definition Classes
    FlatMap
  5. abstract def handleErrorWith[A](fa: F[A])(f: (Throwable) => F[A]): F[A]
    Definition Classes
    ApplicativeError
  6. abstract def pure[A](x: A): F[A]
    Definition Classes
    Applicative
  7. abstract def racePair[A, B](fa: F[A], fb: F[B]): F[Either[(A, Fiber[F, B]), (Fiber[F, A], B)]]

    Run two tasks concurrently, creating a race between them and returns a pair containing both the winner's successful value and the loser represented as a still-unfinished fiber.

    Run two tasks concurrently, creating a race between them and returns a pair containing both the winner's successful value and the loser represented as a still-unfinished fiber.

    If the first task completes in error, then the result will complete in error, the other task being canceled.

    On usage the user has the option of canceling the losing task, this being equivalent with plain race:

    val ioA: IO[A] = ???
    val ioB: IO[B] = ???
    
    Concurrent[IO].racePair(ioA, ioB).flatMap {
      case Left((a, fiberB)) =>
        fiberB.cancel.map(_ => a)
      case Right((fiberA, b)) =>
        fiberA.cancel.map(_ => b)
    }

    See race for a simpler version that cancels the loser immediately.

  8. abstract def raiseError[A](e: Throwable): F[A]
    Definition Classes
    ApplicativeError
  9. abstract def start[A](fa: F[A]): F[Fiber[F, A]]

    Start concurrent execution of the source suspended in the F context.

    Start concurrent execution of the source suspended in the F context.

    Returns a Fiber that can be used to either join or cancel the running computation, being similar in spirit (but not in implementation) to starting a thread.

    See also

    background for a safer alternative.

  10. abstract def tailRecM[A, B](a: A)(f: (A) => F[Either[A, B]]): F[B]
    Definition Classes
    FlatMap
  11. abstract def suspend[A](thunk: => F[A]): F[A]

    Suspends the evaluation of an F reference.

    Suspends the evaluation of an F reference.

    Equivalent to FlatMap.flatten for pure expressions, the purpose of this function is to suspend side effects in F.

    Definition Classes
    Sync
    Annotations
    @deprecated
    Deprecated

    (Since version 2.4.0) use defer

Concrete Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def *>[A, B](fa: F[A])(fb: F[B]): F[B]
    Definition Classes
    Apply
    Annotations
    @inline()
  4. final def <*[A, B](fa: F[A])(fb: F[B]): F[A]
    Definition Classes
    Apply
    Annotations
    @inline()
  5. final def <*>[A, B](ff: F[(A) => B])(fa: F[A]): F[B]
    Definition Classes
    Apply
    Annotations
    @inline()
  6. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  7. def adaptError[A](fa: F[A])(pf: PartialFunction[Throwable, Throwable]): F[A]
    Definition Classes
    MonadError → ApplicativeError
  8. def ap[A, B](ff: F[(A) => B])(fa: F[A]): F[B]
    Definition Classes
    FlatMap → Apply
  9. def ap10[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, Z](f: F[(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9) => Z])(f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9]): F[Z]
    Definition Classes
    ApplyArityFunctions
  10. def ap11[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, Z](f: F[(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10) => Z])(f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9], f10: F[A10]): F[Z]
    Definition Classes
    ApplyArityFunctions
  11. def ap12[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, Z](f: F[(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11) => Z])(f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9], f10: F[A10], f11: F[A11]): F[Z]
    Definition Classes
    ApplyArityFunctions
  12. def ap13[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, Z](f: F[(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12) => Z])(f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9], f10: F[A10], f11: F[A11], f12: F[A12]): F[Z]
    Definition Classes
    ApplyArityFunctions
  13. def ap14[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, Z](f: F[(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13) => Z])(f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9], f10: F[A10], f11: F[A11], f12: F[A12], f13: F[A13]): F[Z]
    Definition Classes
    ApplyArityFunctions
  14. def ap15[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, Z](f: F[(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14) => Z])(f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9], f10: F[A10], f11: F[A11], f12: F[A12], f13: F[A13], f14: F[A14]): F[Z]
    Definition Classes
    ApplyArityFunctions
  15. def ap16[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, Z](f: F[(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15) => Z])(f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9], f10: F[A10], f11: F[A11], f12: F[A12], f13: F[A13], f14: F[A14], f15: F[A15]): F[Z]
    Definition Classes
    ApplyArityFunctions
  16. def ap17[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, Z](f: F[(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16) => Z])(f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9], f10: F[A10], f11: F[A11], f12: F[A12], f13: F[A13], f14: F[A14], f15: F[A15], f16: F[A16]): F[Z]
    Definition Classes
    ApplyArityFunctions
  17. def ap18[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, Z](f: F[(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17) => Z])(f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9], f10: F[A10], f11: F[A11], f12: F[A12], f13: F[A13], f14: F[A14], f15: F[A15], f16: F[A16], f17: F[A17]): F[Z]
    Definition Classes
    ApplyArityFunctions
  18. def ap19[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, Z](f: F[(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18) => Z])(f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9], f10: F[A10], f11: F[A11], f12: F[A12], f13: F[A13], f14: F[A14], f15: F[A15], f16: F[A16], f17: F[A17], f18: F[A18]): F[Z]
    Definition Classes
    ApplyArityFunctions
  19. def ap2[A, B, Z](ff: F[(A, B) => Z])(fa: F[A], fb: F[B]): F[Z]
    Definition Classes
    FlatMap → Apply
  20. def ap20[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, Z](f: F[(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19) => Z])(f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9], f10: F[A10], f11: F[A11], f12: F[A12], f13: F[A13], f14: F[A14], f15: F[A15], f16: F[A16], f17: F[A17], f18: F[A18], f19: F[A19]): F[Z]
    Definition Classes
    ApplyArityFunctions
  21. def ap21[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, Z](f: F[(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20) => Z])(f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9], f10: F[A10], f11: F[A11], f12: F[A12], f13: F[A13], f14: F[A14], f15: F[A15], f16: F[A16], f17: F[A17], f18: F[A18], f19: F[A19], f20: F[A20]): F[Z]
    Definition Classes
    ApplyArityFunctions
  22. def ap22[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, Z](f: F[(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21) => Z])(f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9], f10: F[A10], f11: F[A11], f12: F[A12], f13: F[A13], f14: F[A14], f15: F[A15], f16: F[A16], f17: F[A17], f18: F[A18], f19: F[A19], f20: F[A20], f21: F[A21]): F[Z]
    Definition Classes
    ApplyArityFunctions
  23. def ap3[A0, A1, A2, Z](f: F[(A0, A1, A2) => Z])(f0: F[A0], f1: F[A1], f2: F[A2]): F[Z]
    Definition Classes
    ApplyArityFunctions
  24. def ap4[A0, A1, A2, A3, Z](f: F[(A0, A1, A2, A3) => Z])(f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3]): F[Z]
    Definition Classes
    ApplyArityFunctions
  25. def ap5[A0, A1, A2, A3, A4, Z](f: F[(A0, A1, A2, A3, A4) => Z])(f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4]): F[Z]
    Definition Classes
    ApplyArityFunctions
  26. def ap6[A0, A1, A2, A3, A4, A5, Z](f: F[(A0, A1, A2, A3, A4, A5) => Z])(f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5]): F[Z]
    Definition Classes
    ApplyArityFunctions
  27. def ap7[A0, A1, A2, A3, A4, A5, A6, Z](f: F[(A0, A1, A2, A3, A4, A5, A6) => Z])(f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6]): F[Z]
    Definition Classes
    ApplyArityFunctions
  28. def ap8[A0, A1, A2, A3, A4, A5, A6, A7, Z](f: F[(A0, A1, A2, A3, A4, A5, A6, A7) => Z])(f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7]): F[Z]
    Definition Classes
    ApplyArityFunctions
  29. def ap9[A0, A1, A2, A3, A4, A5, A6, A7, A8, Z](f: F[(A0, A1, A2, A3, A4, A5, A6, A7, A8) => Z])(f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8]): F[Z]
    Definition Classes
    ApplyArityFunctions
  30. def as[A, B](fa: F[A], b: B): F[B]
    Definition Classes
    Functor
  31. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  32. def attempt[A](fa: F[A]): F[Either[Throwable, A]]
    Definition Classes
    ApplicativeError
  33. def attemptNarrow[EE <: Throwable, A](fa: F[A])(implicit tag: ClassTag[EE], ev: <:<[EE, Throwable]): F[Either[EE, A]]
    Definition Classes
    ApplicativeError
  34. def attemptT[A](fa: F[A]): EitherT[F, Throwable, A]
    Definition Classes
    ApplicativeError
  35. def attemptTap[A, B](fa: F[A])(f: (Either[Throwable, A]) => F[B]): F[A]
    Definition Classes
    MonadError
  36. def background[A](fa: F[A]): Resource[F, F[A]]

    Returns a resource that will start execution of the effect in the background.

    Returns a resource that will start execution of the effect in the background.

    In case the resource is closed while the effect is still running (e.g. due to a failure in use), the background action will be canceled.

    A basic example with IO:

    val longProcess = (IO.sleep(5.seconds) *> IO(println("Ping!"))).foreverM
    
    val srv: Resource[IO, ServerBinding[IO]] = for {
      _ <- longProcess.background
      server <- server.run
    } yield server
    
    val application = srv.use(binding => IO(println("Bound to " + binding)) *> IO.never)

    Here, we are starting a background process as part of the application's startup. Afterwards, we initialize a server. Then, we use that server forever using IO.never. This will ensure we never close the server resource unless somebody cancels the whole application action.

    If at some point of using the resource you want to wait for the result of the background action, you can do so by sequencing the value inside the resource (it's equivalent to join on Fiber).

    This will start the background process, run another action, and wait for the result of the background process:

    longProcess.background.use(await => anotherProcess *> await)

    In case the result of such an action is canceled, both processes will receive cancelation signals. The same result can be achieved by using anotherProcess &> longProcess with the Parallel type class syntax.

  37. def bracket[A, B](acquire: F[A])(use: (A) => F[B])(release: (A) => F[Unit]): F[B]

    Operation meant for specifying tasks with safe resource acquisition and release in the face of errors and interruption.

    Operation meant for specifying tasks with safe resource acquisition and release in the face of errors and interruption.

    This operation provides the equivalent of try/catch/finally statements in mainstream imperative languages for resource acquisition and release.

    acquire

    is an action that "acquires" some expensive resource, that needs to be used and then discarded

    use

    is the action that uses the newly allocated resource and that will provide the final result

    release

    is the action that's supposed to release the allocated resource after use is done, regardless of its exit condition. Throwing inside this function is undefined behavior since it's left to the implementation.

    Definition Classes
    Bracket
  38. def cancelable[A](k: ((Either[Throwable, A]) => Unit) => CancelToken[F]): F[A]

    Creates a cancelable F[A] instance that executes an asynchronous process on evaluation.

    Creates a cancelable F[A] instance that executes an asynchronous process on evaluation.

    This builder accepts a registration function that is being injected with a side-effectful callback, to be called when the asynchronous process is complete with a final result.

    The registration function is also supposed to return a CancelToken, which is nothing more than an alias for F[Unit], capturing the logic necessary for canceling the asynchronous process for as long as it is still active.

    Example:

    import java.util.concurrent.ScheduledExecutorService
    import scala.concurrent.duration._
    
    def sleep[F[_]](d: FiniteDuration)
      (implicit F: Concurrent[F], ec: ScheduledExecutorService): F[Unit] = {
    
      F.cancelable { cb =>
        // Schedules task to run after delay
        val run = new Runnable { def run() = cb(Right(())) }
        val future = ec.schedule(run, d.length, d.unit)
    
        // Cancellation logic, suspended in F
        F.delay(future.cancel(true))
      }
    }
  39. def catchNonFatal[A](a: => A)(implicit ev: <:<[Throwable, Throwable]): F[A]
    Definition Classes
    ApplicativeError
  40. def catchNonFatalEval[A](a: Eval[A])(implicit ev: <:<[Throwable, Throwable]): F[A]
    Definition Classes
    ApplicativeError
  41. def catchOnly[T >: Null <: Throwable]: CatchOnlyPartiallyApplied[T, F, Throwable]
    Definition Classes
    ApplicativeError
  42. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
  43. def compose[G[_]](implicit arg0: Applicative[G]): Applicative[[α]F[G[α]]]
    Definition Classes
    Applicative
  44. def compose[G[_]](implicit arg0: Apply[G]): Apply[[α]F[G[α]]]
    Definition Classes
    Apply
  45. def compose[G[_]](implicit arg0: Functor[G]): Functor[[α]F[G[α]]]
    Definition Classes
    Functor
  46. def compose[G[_]](implicit arg0: Invariant[G]): Invariant[[α]F[G[α]]]
    Definition Classes
    Invariant
  47. def composeApply[G[_]](implicit arg0: Apply[G]): InvariantSemigroupal[[α]F[G[α]]]
    Definition Classes
    InvariantSemigroupal
  48. def composeContravariant[G[_]](implicit arg0: Contravariant[G]): Contravariant[[α]F[G[α]]]
    Definition Classes
    Functor → Invariant
  49. def composeContravariantMonoidal[G[_]](implicit arg0: ContravariantMonoidal[G]): ContravariantMonoidal[[α]F[G[α]]]
    Definition Classes
    Applicative
  50. def composeFunctor[G[_]](implicit arg0: Functor[G]): Invariant[[α]F[G[α]]]
    Definition Classes
    Invariant
  51. def continual[A, B](fa: F[A])(f: (Either[Throwable, A]) => F[B]): F[B]

    If no interruption happens during the execution of this method, it behaves like .attempt.flatMap.

    If no interruption happens during the execution of this method, it behaves like .attempt.flatMap.

    Unlike .attempt.flatMap however, in the presence of interruption this method offers the _continual guarantee_: fa is interruptible, but if it completes execution, the effects of f are guaranteed to execute. This does not hold for attempt.flatMap since interruption can happen in between flatMap steps.

    The typical use case for this function arises in the implementation of concurrent abstractions, where you have asynchronous operations waiting on some condition (which have to be interruptible), mixed with operations that modify some shared state if the condition holds true (which need to be guaranteed to happen or the state will be inconsistent).

    Note that for the use case above: - We cannot use:

    waitingOp.bracket(..., modifyOp)

    because it makes waitingOp uninterruptible.

    - We cannot use

    waitingOp.guaranteeCase {
      case Success => modifyOp(???)
      ...

    if we need to use the result of waitingOp.

    - We cannot use

    waitingOp.attempt.flatMap(modifyOp)

    because it could be interrupted after waitingOp is done, but before modifyOp executes.

    To access this implementation as a standalone function, you can use Concurrent.continual in the companion object.

  52. final def defer[A](fa: => F[A]): F[A]

    Alias for suspend that suspends the evaluation of an F reference and implements cats.Defer typeclass.

    Alias for suspend that suspends the evaluation of an F reference and implements cats.Defer typeclass.

    Definition Classes
    Sync → Defer
    Annotations
    @nowarn()
  53. def delay[A](thunk: => A): F[A]

    Lifts any by-name parameter into the F context.

    Lifts any by-name parameter into the F context.

    Equivalent to Applicative.pure for pure expressions, the purpose of this function is to suspend side effects in F.

    Definition Classes
    Sync
  54. def ensure[A](fa: F[A])(error: => Throwable)(predicate: (A) => Boolean): F[A]
    Definition Classes
    MonadError
  55. def ensureOr[A](fa: F[A])(error: (A) => Throwable)(predicate: (A) => Boolean): F[A]
    Definition Classes
    MonadError
  56. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  57. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  58. def fix[A](fn: (F[A]) => F[A]): F[A]
    Definition Classes
    Defer
  59. def flatTap[A, B](fa: F[A])(f: (A) => F[B]): F[A]
    Definition Classes
    FlatMap
  60. def flatten[A](ffa: F[F[A]]): F[A]
    Definition Classes
    FlatMap
  61. final def fmap[A, B](fa: F[A])(f: (A) => B): F[B]
    Definition Classes
    Functor
  62. def foreverM[A, B](fa: F[A]): F[B]
    Definition Classes
    FlatMap
  63. def fproduct[A, B](fa: F[A])(f: (A) => B): F[(A, B)]
    Definition Classes
    Functor
  64. def fproductLeft[A, B](fa: F[A])(f: (A) => B): F[(B, A)]
    Definition Classes
    Functor
  65. def fromEither[A](x: Either[Throwable, A]): F[A]
    Definition Classes
    ApplicativeError
  66. def fromOption[A](oa: Option[A], ifEmpty: => Throwable): F[A]
    Definition Classes
    ApplicativeError
  67. def fromTry[A](t: Try[A])(implicit ev: <:<[Throwable, Throwable]): F[A]
    Definition Classes
    ApplicativeError
  68. def fromValidated[A](x: Validated[Throwable, A]): F[A]
    Definition Classes
    ApplicativeError
  69. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  70. def guarantee[A](fa: F[A])(finalizer: F[Unit]): F[A]

    Executes the given finalizer when the source is finished, either in success or in error, or if canceled.

    Executes the given finalizer when the source is finished, either in success or in error, or if canceled.

    This variant of guaranteeCase evaluates the given finalizer regardless of how the source gets terminated:

    • normal completion
    • completion in error
    • cancelation

    This equivalence always holds:

    F.guarantee(fa)(f) <-> F.bracket(F.unit)(_ => fa)(_ => f)

    As best practice, it's not a good idea to release resources via guaranteeCase in polymorphic code. Prefer bracket for the acquisition and release of resources.

    Definition Classes
    Bracket
    See also

    guaranteeCase for the version that can discriminate between termination conditions

    bracket for the more general operation

  71. def guaranteeCase[A](fa: F[A])(finalizer: (ExitCase[Throwable]) => F[Unit]): F[A]

    Executes the given finalizer when the source is finished, either in success or in error, or if canceled, allowing for differentiating between exit conditions.

    Executes the given finalizer when the source is finished, either in success or in error, or if canceled, allowing for differentiating between exit conditions.

    This variant of guarantee injects an ExitCase in the provided function, allowing one to make a difference between:

    • normal completion
    • completion in error
    • cancelation

    This equivalence always holds:

    F.guaranteeCase(fa)(f) <-> F.bracketCase(F.unit)(_ => fa)((_, e) => f(e))

    As best practice, it's not a good idea to release resources via guaranteeCase in polymorphic code. Prefer bracketCase for the acquisition and release of resources.

    Definition Classes
    Bracket
    See also

    guarantee for the simpler version

    bracketCase for the more general operation

  72. def handleError[A](fa: F[A])(f: (Throwable) => A): F[A]
    Definition Classes
    ApplicativeError
  73. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  74. def ifElseM[A](branches: (F[Boolean], F[A])*)(els: F[A]): F[A]
    Definition Classes
    Monad
  75. def ifF[A](fb: F[Boolean])(ifTrue: => A, ifFalse: => A): F[A]
    Definition Classes
    Functor
  76. def ifM[B](fa: F[Boolean])(ifTrue: => F[B], ifFalse: => F[B]): F[B]
    Definition Classes
    FlatMap
  77. def imap[A, B](fa: F[A])(f: (A) => B)(g: (B) => A): F[B]
    Definition Classes
    Functor → Invariant
  78. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  79. def iterateForeverM[A, B](a: A)(f: (A) => F[A]): F[B]
    Definition Classes
    FlatMap
  80. def iterateUntil[A](f: F[A])(p: (A) => Boolean): F[A]
    Definition Classes
    Monad
  81. def iterateUntilM[A](init: A)(f: (A) => F[A])(p: (A) => Boolean): F[A]
    Definition Classes
    Monad
  82. def iterateWhile[A](f: F[A])(p: (A) => Boolean): F[A]
    Definition Classes
    Monad
  83. def iterateWhileM[A](init: A)(f: (A) => F[A])(p: (A) => Boolean): F[A]
    Definition Classes
    Monad
  84. def lift[A, B](f: (A) => B): (F[A]) => F[B]
    Definition Classes
    Functor
  85. def liftIO[A](ioa: IO[A]): F[A]

    Inherited from LiftIO, defines a conversion from IO in terms of the Concurrent type class.

    Inherited from LiftIO, defines a conversion from IO in terms of the Concurrent type class.

    N.B. expressing this conversion in terms of Concurrent and its capabilities means that the resulting F is cancelable in case the source IO is.

    To access this implementation as a standalone function, you can use Concurrent.liftIO (on the object companion).

    Definition Classes
    ConcurrentAsyncLiftIO
  86. def map[A, B](fa: F[A])(f: (A) => B): F[B]
    Definition Classes
    Monad → Applicative → Functor
  87. def map10[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9])(f: (A0, A1, A2, A3, A4, A5, A6, A7, A8, A9) => Z): F[Z]
    Definition Classes
    ApplyArityFunctions
  88. def map11[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9], f10: F[A10])(f: (A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10) => Z): F[Z]
    Definition Classes
    ApplyArityFunctions
  89. def map12[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9], f10: F[A10], f11: F[A11])(f: (A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11) => Z): F[Z]
    Definition Classes
    ApplyArityFunctions
  90. def map13[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9], f10: F[A10], f11: F[A11], f12: F[A12])(f: (A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12) => Z): F[Z]
    Definition Classes
    ApplyArityFunctions
  91. def map14[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9], f10: F[A10], f11: F[A11], f12: F[A12], f13: F[A13])(f: (A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13) => Z): F[Z]
    Definition Classes
    ApplyArityFunctions
  92. def map15[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9], f10: F[A10], f11: F[A11], f12: F[A12], f13: F[A13], f14: F[A14])(f: (A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14) => Z): F[Z]
    Definition Classes
    ApplyArityFunctions
  93. def map16[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9], f10: F[A10], f11: F[A11], f12: F[A12], f13: F[A13], f14: F[A14], f15: F[A15])(f: (A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15) => Z): F[Z]
    Definition Classes
    ApplyArityFunctions
  94. def map17[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9], f10: F[A10], f11: F[A11], f12: F[A12], f13: F[A13], f14: F[A14], f15: F[A15], f16: F[A16])(f: (A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16) => Z): F[Z]
    Definition Classes
    ApplyArityFunctions
  95. def map18[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9], f10: F[A10], f11: F[A11], f12: F[A12], f13: F[A13], f14: F[A14], f15: F[A15], f16: F[A16], f17: F[A17])(f: (A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17) => Z): F[Z]
    Definition Classes
    ApplyArityFunctions
  96. def map19[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9], f10: F[A10], f11: F[A11], f12: F[A12], f13: F[A13], f14: F[A14], f15: F[A15], f16: F[A16], f17: F[A17], f18: F[A18])(f: (A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18) => Z): F[Z]
    Definition Classes
    ApplyArityFunctions
  97. def map2[A, B, Z](fa: F[A], fb: F[B])(f: (A, B) => Z): F[Z]
    Definition Classes
    FlatMap → Apply
  98. def map20[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9], f10: F[A10], f11: F[A11], f12: F[A12], f13: F[A13], f14: F[A14], f15: F[A15], f16: F[A16], f17: F[A17], f18: F[A18], f19: F[A19])(f: (A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19) => Z): F[Z]
    Definition Classes
    ApplyArityFunctions
  99. def map21[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9], f10: F[A10], f11: F[A11], f12: F[A12], f13: F[A13], f14: F[A14], f15: F[A15], f16: F[A16], f17: F[A17], f18: F[A18], f19: F[A19], f20: F[A20])(f: (A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20) => Z): F[Z]
    Definition Classes
    ApplyArityFunctions
  100. def map22[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9], f10: F[A10], f11: F[A11], f12: F[A12], f13: F[A13], f14: F[A14], f15: F[A15], f16: F[A16], f17: F[A17], f18: F[A18], f19: F[A19], f20: F[A20], f21: F[A21])(f: (A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21) => Z): F[Z]
    Definition Classes
    ApplyArityFunctions
  101. def map2Eval[A, B, Z](fa: F[A], fb: Eval[F[B]])(f: (A, B) => Z): Eval[F[Z]]
    Definition Classes
    FlatMap → Apply
  102. def map3[A0, A1, A2, Z](f0: F[A0], f1: F[A1], f2: F[A2])(f: (A0, A1, A2) => Z): F[Z]
    Definition Classes
    ApplyArityFunctions
  103. def map4[A0, A1, A2, A3, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3])(f: (A0, A1, A2, A3) => Z): F[Z]
    Definition Classes
    ApplyArityFunctions
  104. def map5[A0, A1, A2, A3, A4, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4])(f: (A0, A1, A2, A3, A4) => Z): F[Z]
    Definition Classes
    ApplyArityFunctions
  105. def map6[A0, A1, A2, A3, A4, A5, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5])(f: (A0, A1, A2, A3, A4, A5) => Z): F[Z]
    Definition Classes
    ApplyArityFunctions
  106. def map7[A0, A1, A2, A3, A4, A5, A6, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6])(f: (A0, A1, A2, A3, A4, A5, A6) => Z): F[Z]
    Definition Classes
    ApplyArityFunctions
  107. def map8[A0, A1, A2, A3, A4, A5, A6, A7, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7])(f: (A0, A1, A2, A3, A4, A5, A6, A7) => Z): F[Z]
    Definition Classes
    ApplyArityFunctions
  108. def map9[A0, A1, A2, A3, A4, A5, A6, A7, A8, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8])(f: (A0, A1, A2, A3, A4, A5, A6, A7, A8) => Z): F[Z]
    Definition Classes
    ApplyArityFunctions
  109. def mproduct[A, B](fa: F[A])(f: (A) => F[B]): F[(A, B)]
    Definition Classes
    FlatMap
  110. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  111. def never[A]: F[A]

    Returns a non-terminating F[_], that never completes with a result, being equivalent to async(_ => ())

    Returns a non-terminating F[_], that never completes with a result, being equivalent to async(_ => ())

    Definition Classes
    Async
  112. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  113. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  114. def onCancel[A](fa: F[A])(finalizer: F[Unit]): F[A]

    Executes the given finalizer when the source is canceled.

    Executes the given finalizer when the source is canceled.

    The typical use case for this function arises in the implementation of concurrent abstractions, which generally consist of operations that perform asynchronous waiting after concurrently modifying some state: in case the user asks for cancelation, we want to interrupt the waiting operation, and restore the state to its previous value.

    waitingOp.onCancel(restoreState)

    A direct use of bracket is not a good fit for this case as it would make the waiting action uncancelable.

    NOTE: This function handles interruption only, you need to take care of the success and error case elsewhere in your code

    Definition Classes
    Bracket
    See also

    guaranteeCase for the version that can discriminate between termination conditions

    bracket for the more general operation

    Concurrent.continual when you have a use case similar to the cancel/restore example above, but require access to the result of F[A]

  115. def onError[A](fa: F[A])(pf: PartialFunction[Throwable, F[Unit]]): F[A]
    Definition Classes
    ApplicativeError
  116. def point[A](a: A): F[A]
    Definition Classes
    InvariantMonoidal
  117. def product[A, B](fa: F[A], fb: F[B]): F[(A, B)]
    Definition Classes
    FlatMap → Apply → Semigroupal
  118. def productL[A, B](fa: F[A])(fb: F[B]): F[A]
    Definition Classes
    FlatMap → Apply
  119. def productLEval[A, B](fa: F[A])(fb: Eval[F[B]]): F[A]
    Definition Classes
    FlatMap
  120. def productR[A, B](fa: F[A])(fb: F[B]): F[B]
    Definition Classes
    FlatMap → Apply
  121. def productREval[A, B](fa: F[A])(fb: Eval[F[B]]): F[B]
    Definition Classes
    FlatMap
  122. def race[A, B](fa: F[A], fb: F[B]): F[Either[A, B]]

    Run two tasks concurrently and return the first to finish, either in success or error.

    Run two tasks concurrently and return the first to finish, either in success or error. The loser of the race is canceled.

    The two tasks are potentially executed in parallel, the winner being the first that signals a result.

    As an example see Concurrent.timeoutTo

    Also see racePair for a version that does not cancel the loser automatically on successful results.

  123. def raiseUnless(cond: Boolean)(e: => Throwable): F[Unit]
    Definition Classes
    ApplicativeError
  124. def raiseWhen(cond: Boolean)(e: => Throwable): F[Unit]
    Definition Classes
    ApplicativeError
  125. def recover[A](fa: F[A])(pf: PartialFunction[Throwable, A]): F[A]
    Definition Classes
    ApplicativeError
  126. def recoverWith[A](fa: F[A])(pf: PartialFunction[Throwable, F[A]]): F[A]
    Definition Classes
    ApplicativeError
  127. def redeem[A, B](fa: F[A])(recover: (Throwable) => B, f: (A) => B): F[B]
    Definition Classes
    ApplicativeError
  128. def redeemWith[A, B](fa: F[A])(recover: (Throwable) => F[B], bind: (A) => F[B]): F[B]
    Definition Classes
    MonadError
  129. def replicateA[A](n: Int, fa: F[A]): F[List[A]]
    Definition Classes
    Applicative
  130. def rethrow[A, EE <: Throwable](fa: F[Either[EE, A]]): F[A]
    Definition Classes
    MonadError
  131. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  132. def toString(): String
    Definition Classes
    AnyRef → Any
  133. def tuple10[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9]): F[(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9)]
    Definition Classes
    ApplyArityFunctions
  134. def tuple11[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9], f10: F[A10]): F[(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)]
    Definition Classes
    ApplyArityFunctions
  135. def tuple12[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9], f10: F[A10], f11: F[A11]): F[(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11)]
    Definition Classes
    ApplyArityFunctions
  136. def tuple13[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9], f10: F[A10], f11: F[A11], f12: F[A12]): F[(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12)]
    Definition Classes
    ApplyArityFunctions
  137. def tuple14[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9], f10: F[A10], f11: F[A11], f12: F[A12], f13: F[A13]): F[(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13)]
    Definition Classes
    ApplyArityFunctions
  138. def tuple15[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9], f10: F[A10], f11: F[A11], f12: F[A12], f13: F[A13], f14: F[A14]): F[(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14)]
    Definition Classes
    ApplyArityFunctions
  139. def tuple16[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9], f10: F[A10], f11: F[A11], f12: F[A12], f13: F[A13], f14: F[A14], f15: F[A15]): F[(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15)]
    Definition Classes
    ApplyArityFunctions
  140. def tuple17[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9], f10: F[A10], f11: F[A11], f12: F[A12], f13: F[A13], f14: F[A14], f15: F[A15], f16: F[A16]): F[(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16)]
    Definition Classes
    ApplyArityFunctions
  141. def tuple18[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9], f10: F[A10], f11: F[A11], f12: F[A12], f13: F[A13], f14: F[A14], f15: F[A15], f16: F[A16], f17: F[A17]): F[(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17)]
    Definition Classes
    ApplyArityFunctions
  142. def tuple19[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9], f10: F[A10], f11: F[A11], f12: F[A12], f13: F[A13], f14: F[A14], f15: F[A15], f16: F[A16], f17: F[A17], f18: F[A18]): F[(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18)]
    Definition Classes
    ApplyArityFunctions
  143. def tuple2[A, B](f1: F[A], f2: F[B]): F[(A, B)]
    Definition Classes
    ApplyArityFunctions
  144. def tuple20[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9], f10: F[A10], f11: F[A11], f12: F[A12], f13: F[A13], f14: F[A14], f15: F[A15], f16: F[A16], f17: F[A17], f18: F[A18], f19: F[A19]): F[(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19)]
    Definition Classes
    ApplyArityFunctions
  145. def tuple21[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9], f10: F[A10], f11: F[A11], f12: F[A12], f13: F[A13], f14: F[A14], f15: F[A15], f16: F[A16], f17: F[A17], f18: F[A18], f19: F[A19], f20: F[A20]): F[(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20)]
    Definition Classes
    ApplyArityFunctions
  146. def tuple22[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8], f9: F[A9], f10: F[A10], f11: F[A11], f12: F[A12], f13: F[A13], f14: F[A14], f15: F[A15], f16: F[A16], f17: F[A17], f18: F[A18], f19: F[A19], f20: F[A20], f21: F[A21]): F[(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21)]
    Definition Classes
    ApplyArityFunctions
  147. def tuple3[A0, A1, A2, Z](f0: F[A0], f1: F[A1], f2: F[A2]): F[(A0, A1, A2)]
    Definition Classes
    ApplyArityFunctions
  148. def tuple4[A0, A1, A2, A3, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3]): F[(A0, A1, A2, A3)]
    Definition Classes
    ApplyArityFunctions
  149. def tuple5[A0, A1, A2, A3, A4, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4]): F[(A0, A1, A2, A3, A4)]
    Definition Classes
    ApplyArityFunctions
  150. def tuple6[A0, A1, A2, A3, A4, A5, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5]): F[(A0, A1, A2, A3, A4, A5)]
    Definition Classes
    ApplyArityFunctions
  151. def tuple7[A0, A1, A2, A3, A4, A5, A6, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6]): F[(A0, A1, A2, A3, A4, A5, A6)]
    Definition Classes
    ApplyArityFunctions
  152. def tuple8[A0, A1, A2, A3, A4, A5, A6, A7, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7]): F[(A0, A1, A2, A3, A4, A5, A6, A7)]
    Definition Classes
    ApplyArityFunctions
  153. def tuple9[A0, A1, A2, A3, A4, A5, A6, A7, A8, Z](f0: F[A0], f1: F[A1], f2: F[A2], f3: F[A3], f4: F[A4], f5: F[A5], f6: F[A6], f7: F[A7], f8: F[A8]): F[(A0, A1, A2, A3, A4, A5, A6, A7, A8)]
    Definition Classes
    ApplyArityFunctions
  154. def tupleLeft[A, B](fa: F[A], b: B): F[(B, A)]
    Definition Classes
    Functor
  155. def tupleRight[A, B](fa: F[A], b: B): F[(A, B)]
    Definition Classes
    Functor
  156. def uncancelable[A](fa: F[A]): F[A]

    Operation meant for ensuring a given task continues execution even when interrupted.

    Operation meant for ensuring a given task continues execution even when interrupted.

    Definition Classes
    Bracket
  157. def unit: F[Unit]
    Definition Classes
    Applicative → InvariantMonoidal
  158. def unlessA[A](cond: Boolean)(f: => F[A]): F[Unit]
    Definition Classes
    Applicative
  159. def untilDefinedM[A](foa: F[Option[A]]): F[A]
    Definition Classes
    FlatMap
  160. def untilM[G[_], A](f: F[A])(cond: => F[Boolean])(implicit G: Alternative[G]): F[G[A]]
    Definition Classes
    Monad
  161. def untilM_[A](f: F[A])(cond: => F[Boolean]): F[Unit]
    Definition Classes
    Monad
  162. def unzip[A, B](fab: F[(A, B)]): (F[A], F[B])
    Definition Classes
    Functor
  163. def void[A](fa: F[A]): F[Unit]
    Definition Classes
    Functor
  164. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  165. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  166. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  167. def whenA[A](cond: Boolean)(f: => F[A]): F[Unit]
    Definition Classes
    Applicative
  168. def whileM[G[_], A](p: F[Boolean])(body: => F[A])(implicit G: Alternative[G]): F[G[A]]
    Definition Classes
    Monad
  169. def whileM_[A](p: F[Boolean])(body: => F[A]): F[Unit]
    Definition Classes
    Monad
  170. def widen[A, B >: A](fa: F[A]): F[B]
    Definition Classes
    Functor

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated
    Deprecated
  2. def ifA[A](fcond: F[Boolean])(ifTrue: F[A], ifFalse: F[A]): F[A]
    Definition Classes
    Apply
    Annotations
    @deprecated
    Deprecated

    (Since version 2.6.2) Dangerous method, use ifM (a flatMap) or ifF (a map) instead

Inherited from Async[F]

Inherited from LiftIO[F]

Inherited from Sync[F]

Inherited from Defer[F]

Inherited from Bracket[F, Throwable]

Inherited from MonadError[F, Throwable]

Inherited from Monad[F]

Inherited from FlatMap[F]

Inherited from ApplicativeError[F, Throwable]

Inherited from Applicative[F]

Inherited from InvariantMonoidal[F]

Inherited from Apply[F]

Inherited from ApplyArityFunctions[F]

Inherited from InvariantSemigroupal[F]

Inherited from Semigroupal[F]

Inherited from Functor[F]

Inherited from Invariant[F]

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped