Object/Trait

cats.effect

Concurrent

Related Docs: trait Concurrent | package effect

Permalink

object Concurrent extends Serializable

Source
Concurrent.scala
Linear Supertypes
Serializable, Serializable, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Concurrent
  2. Serializable
  3. Serializable
  4. AnyRef
  5. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. trait AllOps[F[_], A] extends Ops[F, A] with Async.AllOps[F, A]

    Permalink
  2. trait Ops[F[_], A] extends AnyRef

    Permalink
  3. trait ToConcurrentOps extends AnyRef

    Permalink

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. def apply[F[_]](implicit instance: Concurrent[F]): Concurrent[F]

    Permalink
    Annotations
    @inline()
  5. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  6. def cancelableF[F[_], A](k: ((Either[Throwable, A]) ⇒ Unit) ⇒ F[CancelToken[F]])(implicit F: Concurrent[F]): F[A]

    Permalink

    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.implicits._
    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(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

  7. implicit def catsEitherTConcurrent[F[_], L](implicit arg0: Concurrent[F]): Concurrent[[γ$0$]EitherT[F, L, γ$0$]]

    Permalink

    Concurrent instance built for cats.data.EitherT values initialized with any F data type that also implements Concurrent.

  8. implicit def catsIorTConcurrent[F[_], L](implicit arg0: Concurrent[F], arg1: Semigroup[L]): Concurrent[[γ$4$]IorT[F, L, γ$4$]]

    Permalink

    Concurrent instance built for cats.data.IorT values initialized with any F data type that also implements Concurrent.

  9. implicit def catsKleisliConcurrent[F[_], R](implicit arg0: Concurrent[F]): Concurrent[[γ$2$]Kleisli[F, R, γ$2$]]

    Permalink

    Concurrent instance built for cats.data.Kleisli values initialized with any F data type that also implements Concurrent.

  10. implicit def catsOptionTConcurrent[F[_]](implicit arg0: Concurrent[F]): Concurrent[[β$1$]OptionT[F, β$1$]]

    Permalink

    Concurrent instance built for cats.data.OptionT values initialized with any F data type that also implements Concurrent.

  11. implicit def catsWriterTConcurrent[F[_], L](implicit arg0: Concurrent[F], arg1: Monoid[L]): Concurrent[[γ$3$]WriterT[F, L, γ$3$]]

    Permalink

    Concurrent instance built for cats.data.WriterT values initialized with any F data type that also implements Concurrent.

  12. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  13. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  14. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  15. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  16. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  17. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  18. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  19. def liftIO[F[_], A](ioa: IO[A])(implicit F: Concurrent[F]): F[A]

    Permalink

    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.

  20. def memoize[F[_], A](f: F[A])(implicit F: Concurrent[F]): F[F[A]]

    Permalink

    Lazily memoizes f.

    Lazily memoizes f. For every time the returned F[F[A]] is bound, the effect f will be performed at most once (when the inner F[A] is bound the first time).

    Note: start can be used for eager memoization.

  21. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  22. object nonInheritedOps extends ToConcurrentOps

    Permalink
  23. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  24. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  25. object ops

    Permalink
  26. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  27. def timeout[F[_], A](fa: F[A], duration: FiniteDuration)(implicit F: Concurrent[F], timer: Timer[F]): F[A]

    Permalink

    Returns an effect that either completes with the result of the source within the specified time duration or otherwise raises a TimeoutException.

    Returns an effect that either completes with the result of the source within the specified time duration or otherwise raises a TimeoutException.

    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

  28. def timeoutTo[F[_], A](fa: F[A], duration: FiniteDuration, fallback: F[A])(implicit F: Concurrent[F], timer: Timer[F]): F[A]

    Permalink

    Returns an effect that either completes with the result of the source within the specified time duration or otherwise evaluates the fallback.

    Returns an effect that either completes with the result of the source within the specified time duration or otherwise evaluates the fallback.

    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

  29. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  30. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  31. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  32. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from Serializable

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped