Class/Object

monix.eval

Task

Related Docs: object Task | package eval

Permalink

sealed abstract class Task[+A] extends Serializable

Task represents a specification for a possibly lazy or asynchronous computation, which when executed will produce an A as a result, along with possible side-effects.

Compared with Future from Scala's standard library, Task does not represent a running computation or a value detached from time, as Task does 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 after runAsync is called and not before that.

Note that Task is conservative in how it spawns logical threads. Transformations like map and flatMap for 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 executing runAsync.

Self Type
Task[A]
Source
Task.scala
Linear Supertypes
Serializable, Serializable, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Task
  2. Serializable
  3. Serializable
  4. AnyRef
  5. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

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. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  6. def coeval(implicit s: Scheduler): Coeval[Either[CancelableFuture[A], A]]

    Permalink

    Transforms a Task into a Coeval that tries to execute the source synchronously, returning either Right(value) in case a value is available immediately, or Left(future) in case we have an asynchronous boundary.

  7. def delayExecution(timespan: FiniteDuration): Task[A]

    Permalink

    Returns a task that waits for the specified timespan before executing and mirroring the result of the source.

  8. def delayExecutionWith(trigger: Task[Any]): Task[A]

    Permalink

    Returns a task that waits for the specified trigger to succeed before mirroring the result of the source.

    Returns a task that waits for the specified trigger to succeed before mirroring the result of the source.

    If the trigger ends in error, then the resulting task will also end in error.

  9. def delayResult(timespan: FiniteDuration): Task[A]

    Permalink

    Returns a task that executes the source immediately on runAsync, but before emitting the onSuccess result for the specified duration.

    Returns a task that executes the source immediately on runAsync, but before emitting the onSuccess result for the specified duration.

    Note that if an error happens, then it is streamed immediately with no delay.

  10. def delayResultBySelector[B](selector: (A) ⇒ Task[B]): Task[A]

    Permalink

    Returns a task that executes the source immediately on runAsync, but before emitting the onSuccess result for the specified duration.

    Returns a task that executes the source immediately on runAsync, but before emitting the onSuccess result for the specified duration.

    Note that if an error happens, then it is streamed immediately with no delay.

  11. def dematerialize[B](implicit ev: <:<[A, Try[B]]): Task[B]

    Permalink

    Dematerializes the source's result from a Try.

  12. def dematerializeAttempt[B](implicit ev: <:<[A, Attempt[B]]): Task[B]

    Permalink

    Dematerializes the source's result from an Attempt.

  13. def doOnFinish(f: (Option[Throwable]) ⇒ Task[Unit]): Task[A]

    Permalink

    Returns a new Task in which f is scheduled to be run on completion.

    Returns a new Task in which f is scheduled to be run on completion. This would typically be used to release any resources acquired by this Task.

    The returned Task completes when both the source and the task returned by f complete.

  14. final def eq(arg0: AnyRef): Boolean

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

    Permalink
    Definition Classes
    AnyRef → Any
  16. def executeOn(s: Scheduler): Task[A]

    Permalink

    Mirrors the given source Task, but upon execution ensure that evaluation forks into a separate (logical) thread.

    Mirrors the given source Task, but upon execution ensure that evaluation forks into a separate (logical) thread.

    The given Scheduler will be used for execution of the Task, effectively overriding the Scheduler that's passed in runAsync. Thus you can execute a whole Task on a separate thread-pool, useful for example in case of doing I/O.

    NOTE: the logic one cares about won't necessarily end up executed on the given scheduler, or for transformations that happen from here on. It all depends on what overrides or asynchronous boundaries happen. But this function guarantees that the this Task run-loop begins executing on the given scheduler.

    s

    is the scheduler to use for execution

  17. def failed: Task[Throwable]

    Permalink

    Returns a failed projection of this task.

    Returns a failed projection of this task.

    The failed projection is a future holding a value of type Throwable, emitting a value which is the throwable of the original task in case the original task fails, otherwise if the source succeeds, then it fails with a NoSuchElementException.

  18. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  19. def flatMap[B](f: (A) ⇒ Task[B]): Task[B]

    Permalink

    Creates a new Task by applying a function to the successful result of the source Task, and returns a task equivalent to the result of the function.

  20. def flatten[B](implicit ev: <:<[A, Task[B]]): Task[B]

    Permalink

    Given a source Task that emits another Task, this function flattens the result, returning a Task equivalent to the emitted Task by the source.

  21. final def getClass(): Class[_]

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

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

    Permalink
    Definition Classes
    Any
  24. def map[B](f: (A) ⇒ B): Task[B]

    Permalink

    Returns a new Task that applies the mapping function to the element emitted by the source.

  25. def materialize: Task[Try[A]]

    Permalink

    Creates a new Task that will expose any triggered error from the source.

  26. def materializeAttempt: Task[Attempt[A]]

    Permalink

    Creates a new Task that will expose any triggered error from the source.

  27. def memoize: Task[A]

    Permalink

    Memoizes the result on the computation and reuses it on subsequent invocations of runAsync.

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

    Permalink
    Definition Classes
    AnyRef
  29. final def notify(): Unit

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

    Permalink
    Definition Classes
    AnyRef
  31. def onErrorFallbackTo[B >: A](that: Task[B]): Task[B]

    Permalink

    Creates a new task that in case of error will fallback to the given backup task.

  32. def onErrorHandle[U >: A](f: (Throwable) ⇒ U): Task[U]

    Permalink

    Creates a new task that will handle any matching throwable that this task might emit.

    Creates a new task that will handle any matching throwable that this task might emit.

    See onErrorRecover for the version that takes a partial function.

  33. def onErrorHandleWith[B >: A](f: (Throwable) ⇒ Task[B]): Task[B]

    Permalink

    Creates a new task that will handle any matching throwable that this task might emit by executing another task.

    Creates a new task that will handle any matching throwable that this task might emit by executing another task.

    See onErrorRecoverWith for the version that takes a partial function.

  34. def onErrorRecover[U >: A](pf: PartialFunction[Throwable, U]): Task[U]

    Permalink

    Creates a new task that on error will try to map the error to another value using the provided partial function.

    Creates a new task that on error will try to map the error to another value using the provided partial function.

    See onErrorHandle for the version that takes a total function.

  35. def onErrorRecoverWith[B >: A](pf: PartialFunction[Throwable, Task[B]]): Task[B]

    Permalink

    Creates a new task that will try recovering from an error by matching it with another task using the given partial function.

    Creates a new task that will try recovering from an error by matching it with another task using the given partial function.

    See onErrorHandleWith for the version that takes a total function.

  36. def onErrorRestart(maxRetries: Long): Task[A]

    Permalink

    Creates a new task that in case of error will retry executing the source again and again, until it succeeds.

    Creates a new task that in case of error will retry executing the source again and again, until it succeeds.

    In case of continuous failure the total number of executions will be maxRetries + 1.

  37. def onErrorRestartIf(p: (Throwable) ⇒ Boolean): Task[A]

    Permalink

    Creates a new task that in case of error will retry executing the source again and again, until it succeeds.

    Creates a new task that in case of error will retry executing the source again and again, until it succeeds.

    In case of continuous failure the total number of executions will be maxRetries + 1.

  38. def restartUntil(p: (A) ⇒ Boolean): Task[A]

    Permalink

    Given a predicate function, keep retrying the task until the function returns true.

  39. def runAsync(implicit s: Scheduler): CancelableFuture[A]

    Permalink

    Triggers the asynchronous execution.

    Triggers the asynchronous execution.

    returns

    a CancelableFuture that can be used to extract the result or to cancel a running task.

  40. def runAsync(f: (Try[A]) ⇒ Unit)(implicit s: Scheduler): Cancelable

    Permalink

    Triggers the asynchronous execution.

    Triggers the asynchronous execution.

    f

    is a callback that will be invoked upon completion.

    returns

    a Cancelable that can be used to cancel a running task

  41. def runAsync(cb: Callback[A])(implicit s: Scheduler): Cancelable

    Permalink

    Triggers the asynchronous execution.

    Triggers the asynchronous execution.

    cb

    is a callback that will be invoked upon completion.

    returns

    a Cancelable that can be used to cancel a running task

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

    Permalink
    Definition Classes
    AnyRef
  43. def timeout(after: FiniteDuration): Task[A]

    Permalink

    Returns a Task that mirrors the source Task but that triggers a TimeoutException in case the given duration passes without the task emitting any item.

  44. def timeoutTo[B >: A](after: FiniteDuration, backup: Task[B]): Task[B]

    Permalink

    Returns a Task that mirrors the source Task but switches to the given backup Task in case the given duration passes without the source emitting any item.

  45. def toReactivePublisher[B >: A](implicit s: Scheduler): Publisher[B]

    Permalink

    Converts a Task to an org.reactivestreams.Publisher that emits a single item on success, or just the error on failure.

    Converts a Task to an org.reactivestreams.Publisher that emits a single item on success, or just the error on failure.

    See reactive-streams.org for the Reactive Streams specification.

  46. def toString(): String

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

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

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

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  50. def zip[B](that: Task[B]): Task[(A, B)]

    Permalink

    Zips the values of this and that task, and creates a new task that will emit the tuple of their results.

  51. def zipMap[B, C](that: Task[B])(f: (A, B) ⇒ C): Task[C]

    Permalink

    Zips the values of this and that and applies the given mapping function on their results.

Inherited from Serializable

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped