package eval
- Alphabetic
- Public
- All
Type Members
-
trait
Callback
[-T] extends (Try[T]) ⇒ Unit with Serializable
Represents a callback that should be called asynchronously with the result of a computation.
Represents a callback that should be called asynchronously with the result of a computation. Used by Task to signal the completion of asynchronous computations on
runAsync.The
onSuccessmethod should be called only once, with the successful result, whereasonErrorshould be called if the result is an error. -
sealed abstract
class
Coeval
[+A] extends Serializable
Coevalrepresents lazy computations that can execute synchronously.Coevalrepresents lazy computations that can execute synchronously.Word definition and origin:
- Having the same age or date of origin; a contemporary; synchronous.
- From the Latin "coævus": com- ("equal") in combination with aevum (aevum, "age").
- The constructor of
Coevalis the dual of an expression that evaluates to anA.
There are three evaluation strategies:
- Now or Error: for describing strict values, evaluated immediately
- Once: expressions evaluated a single time
- Always: expressions evaluated every time the value is needed
The
OnceandAlwaysare both lazy strategies whileNowandErrorare eager.OnceandAlwaysare distinguished from each other only by memoization: once evaluatedOncewill save the value to be returned immediately if it is needed again.Alwayswill run its computation every time.Both
NowandErrorare represented by the Attempt trait, a sub-type of Coeval that can be used as a replacement for Scala's ownTrytype.Coevalsupports stack-safe lazy computation via the .map and .flatMap methods, which use an internal trampoline to avoid stack overflows. Computation done within .map and .flatMap is always done lazily, even when applied to aNowinstance. -
sealed abstract
class
Task
[+A] extends Serializable
Taskrepresents a specification for a possibly lazy or asynchronous computation, which when executed will produce anAas a result, along with possible side-effects.Taskrepresents a specification for a possibly lazy or asynchronous computation, which when executed will produce anAas a result, along with possible side-effects.Compared with
Futurefrom Scala's standard library,Taskdoes not represent a running computation or a value detached from time, asTaskdoes not execute anything when working with its builders or operators and it does not submit any work into any thread-pool, the execution eventually taking place only afterrunAsyncis called and not before that.Note that
Taskis conservative in how it spawns logical threads. Transformations likemapandflatMapfor example will default to being executed on the logical thread on which the asynchronous computation was started. But one shouldn't make assumptions about how things will end up executed, as ultimately it is the implementation's job to decide on the best execution model. All you are guaranteed is asynchronous execution after executingrunAsync. -
trait
TaskApp
extends AnyRef
Safe
Apptype that runs a Task action.Safe
Apptype that runs a Task action.Clients should implement
run,runl, orrunc.Also available for Scala.js, but without the ability to take arguments and without the blocking in main.
-
final
class
TaskSemaphore
extends Serializable
The
TaskSemaphoreis an asynchronous semaphore implementation that limits the parallelism on task execution.The
TaskSemaphoreis an asynchronous semaphore implementation that limits the parallelism on task execution.The following example instantiates a semaphore with a maximum parallelism of 10:
val semaphore = TaskSemaphore(maxParallelism = 10) def makeRequest(r: HttpRequest): Task[HttpResponse] = ??? // For such a task no more than 10 requests // are allowed to be executed in parallel. val task = semaphore.greenLight(makeRequest(???))
Value Members
- object Callback extends Serializable
- object Coeval extends Serializable
- object Task extends TaskInstances with Serializable
- object TaskSemaphore extends Serializable

This is the API documentation for the Monix library.
Package Overview
monix.execution exposes lower level primitives for dealing with asynchronous execution:
Atomictypes, as alternative tojava.util.concurrent.atomicmonix.eval is for dealing with evaluation of results, thus exposing Task and Coeval.
monix.reactive exposes the
Observablepattern:Observableimplementationsmonix.types implements type-class shims, to be translated to type-classes provided by libraries such as Cats or Scalaz.
monix.cats is the optional integration with the Cats library, providing translations for the types described in
monix.types.monix.scalaz is the optional integration with the Scalaz library, providing translations for the types described in
monix.types.