object Concurrent extends Serializable
- Source
- Concurrent.scala
- Alphabetic
- By Inheritance
- Concurrent
- Serializable
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- trait AllOps[F[_], A] extends Ops[F, A] with Async.AllOps[F, A]
- trait Ops[F[_], A] extends AnyRef
- trait ToConcurrentOps extends AnyRef
- class ops$ extends AnyRef
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def apply[F[_]](implicit instance: Concurrent[F]): Concurrent[F]
Summon an instance of Concurrent for
F
.Summon an instance of Concurrent for
F
.- Annotations
- @inline()
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def cancelableF[F[_], A](k: ((Either[Throwable, A]) => Unit) => F[CancelToken[F]])(implicit F: Concurrent[F]): F[A]
Function that creates an async and cancelable
F[A]
, similar with Concurrent.cancelable, but with the semantics of Async.asyncF.Function that creates an async and cancelable
F[A]
, similar with Concurrent.cancelable, but with the semantics of Async.asyncF.Example building an asynchronous queue, with the state being kept in cats.effect.concurrent.Ref and thus needing
cancelableF
:import cats.syntax.all._ import cats.effect.{CancelToken, Concurrent} import cats.effect.concurrent.Ref import scala.collection.immutable.Queue final class AsyncQueue[F[_], A] private ( ref: Ref[F, AsyncQueue.State[A]]) (implicit F: Concurrent[F]) { import AsyncQueue._ def poll: F[A] = Concurrent.cancelableF { cb => ref.modify { case Await(listeners) => (Await(listeners.enqueue(cb)), F.pure(unregister(cb))) case Available(queue) => queue.dequeueOption match { case None => (Await(Queue(cb)), F.pure(unregister(cb))) case Some((a, queue2)) => (Available(queue2), F.delay(cb(Right(a))).as(unregister(cb))) } }.flatten } def offer(a: A): F[Unit] = { // Left as an exercise for the reader ;-) ??? } private def unregister(cb: Either[Throwable, A] => Unit): CancelToken[F] = ref.update { case Await(listeners) => Await(listeners.filter(_ != cb)) case other => other } } object AsyncQueue { def empty[F[_], A](implicit F: Concurrent[F]): F[AsyncQueue[F, A]] = for { ref <- Ref.of[F, State[A]](Available(Queue.empty)) } yield { new AsyncQueue[F, A](ref) } private sealed trait State[A] private case class Await[A](listeners: Queue[Either[Throwable, A] => Unit]) extends State[A] private case class Available[A](values: Queue[A]) extends State[A] }
Contract
The given generator function will be executed uninterruptedly, via
bracket
, because due to the possibility of auto-cancellation we can have a resource leak otherwise.This means that the task generated by
k
cannot be cancelled while being evaluated. This is in contrast with Async.asyncF, which does allow cancelable tasks.- k
is a function that's going to be injected with a callback, to call on completion, returning an effect that's going to be evaluated to a cancellation token
- implicit def catsEitherTConcurrent[F[_], L](implicit arg0: Concurrent[F]): Concurrent[[γ$0$]EitherT[F, L, γ$0$]]
Concurrent instance built for
cats.data.EitherT
values initialized with anyF
data type that also implementsConcurrent
. - implicit def catsIorTConcurrent[F[_], L](implicit arg0: Concurrent[F], arg1: Semigroup[L]): Concurrent[[γ$4$]IorT[F, L, γ$4$]]
Concurrent instance built for
cats.data.IorT
values initialized with anyF
data type that also implementsConcurrent
. - implicit def catsKleisliConcurrent[F[_], R](implicit arg0: Concurrent[F]): Concurrent[[γ$2$]Kleisli[F, R, γ$2$]]
Concurrent instance built for
cats.data.Kleisli
values initialized with anyF
data type that also implementsConcurrent
. - implicit def catsOptionTConcurrent[F[_]](implicit arg0: Concurrent[F]): Concurrent[[β$1$]OptionT[F, β$1$]]
Concurrent instance built for
cats.data.OptionT
values initialized with anyF
data type that also implementsConcurrent
. - implicit def catsWriterTConcurrent[F[_], L](implicit arg0: Concurrent[F], arg1: Monoid[L]): Concurrent[[γ$3$]WriterT[F, L, γ$3$]]
Concurrent instance built for
cats.data.WriterT
values initialized with anyF
data type that also implementsConcurrent
. - def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
- def continual[F[_], A, B](fa: F[A])(f: (Either[Throwable, A]) => F[B])(implicit F: Concurrent[F]): F[B]
This is the default Concurrent.continual implementation.
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def liftIO[F[_], A](ioa: IO[A])(implicit F: Concurrent[F]): F[A]
Lifts any
IO
value into any data type implementing Concurrent.Lifts any
IO
value into any data type implementing Concurrent.Compared with Async.liftIO, this version preserves the interruptibility of the given
IO
value.This is the default
Concurrent.liftIO
implementation. - def memoize[F[_], A](f: F[A])(implicit F: Concurrent[F]): F[F[A]]
Lazily memoizes
f
.Lazily memoizes
f
. Assuming no cancellation happens, the effectf
will be performed at most once for every time the returnedF[F[A]]
is bound (when the innerF[A]
is bound the first time).If you try to cancel an inner
F[A]
,f
is only interrupted if there are no other active subscribers, whereas if there are,f
keeps running in the background.If
f
is successfully canceled, the next time an innerF[A]
is boundf
will be restarted again. Note that this can mean the effects off
happen more than once.You can look at
Async.memoize
for a version of this function which does not allow cancellation. - final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- val ops: ops$
- def parReplicateAN[M[_], A](n: Long)(replicas: Int, ma: M[A])(implicit M: Concurrent[M], P: Parallel[M]): M[List[A]]
Like
Parallel.parReplicateA
, but limits the degree of parallelism. - def parSequenceN[T[_], M[_], A](n: Long)(tma: T[M[A]])(implicit arg0: Traverse[T], M: Concurrent[M], P: Parallel[M]): M[T[A]]
Like
Parallel.parSequence
, but limits the degree of parallelism. - def parTraverseN[T[_], M[_], A, B](n: Long)(ta: T[A])(f: (A) => M[B])(implicit arg0: Traverse[T], M: Concurrent[M], P: Parallel[M]): M[T[B]]
Like
Parallel.parTraverse
, but limits the degree of parallelism. - final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def timeout[F[_], A](fa: F[A], duration: FiniteDuration)(implicit F: Concurrent[F], timer: Timer[F]): F[A]
Returns an effect that either completes with the result of the source within the specified time
duration
or otherwise raises aTimeoutException
.Returns an effect that either completes with the result of the source within the specified time
duration
or otherwise raises aTimeoutException
.The source is cancelled in the event that it takes longer than the specified time duration to complete.
- duration
is the time span for which we wait for the source to complete; in the event that the specified time has passed without the source completing, a
TimeoutException
is raised
- def timeoutTo[F[_], A](fa: F[A], duration: FiniteDuration, fallback: F[A])(implicit F: Concurrent[F], timer: Timer[F]): F[A]
Returns an effect that either completes with the result of the source within the specified time
duration
or otherwise evaluates thefallback
.Returns an effect that either completes with the result of the source within the specified time
duration
or otherwise evaluates thefallback
.The source is cancelled in the event that it takes longer than the
FiniteDuration
to complete, the evaluation of the fallback happening immediately after that.- duration
is the time span for which we wait for the source to complete; in the event that the specified time has passed without the source completing, the
fallback
gets evaluated- fallback
is the task evaluated after the duration has passed and the source canceled
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- object nonInheritedOps extends ToConcurrentOps
Deprecated Value Members
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable]) @Deprecated
- Deprecated
This is the API documentation for the cats-effect library.
See the cats.effect package for a quick overview.
Links
Canonical documentation links:
Related Cats links (the core):