Packages

  • package root

    This is the API documentation for the Monix library.

    Package Overview

    monix.execution exposes lower level primitives for dealing with asynchronous execution:

    monix.eval is for dealing with evaluation of results, thus exposing Task and Coeval.

    monix.reactive exposes the Observable pattern:

    monix.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.

    Definition Classes
    root
  • package monix
    Definition Classes
    root
  • package execution
    Definition Classes
    monix
  • package atomic

    A small toolkit of classes that support compare-and-swap semantics for safe mutation of variables.

    A small toolkit of classes that support compare-and-swap semantics for safe mutation of variables.

    On top of the JVM, this means dealing with lock-free thread-safe programming. Also works on top of Javascript, with Scala.js, for API compatibility purposes and because it's a useful way to box a value.

    The backbone of Atomic references is this method:

    def compareAndSet(expect: T, update: T): Boolean

    This method atomically sets a variable to the update value if it currently holds the expect value, reporting true on success or false on failure. The classes in this package also contain methods to get and unconditionally set values.

    Building a reference is easy with the provided constructor, which will automatically return the most specific type needed (in the following sample, that's an AtomicDouble, inheriting from AtomicNumber[A]):

    val atomicNumber = Atomic(12.2)
    
    atomicNumber.incrementAndGet()
    // => 13.2

    These also provide useful helpers for atomically mutating of values (i.e. transform, transformAndGet, getAndTransform, etc...) or of numbers of any kind (incrementAndGet, getAndAdd, etc...).

    Definition Classes
    execution
  • package cancelables

    Cancelables represent asynchronous units of work or other things scheduled for execution and whose execution can be canceled.

    Cancelables represent asynchronous units of work or other things scheduled for execution and whose execution can be canceled.

    One use-case is the scheduling done by monix.execution.Scheduler, in which the scheduling methods return a Cancelable, allowing the canceling of the scheduling.

    Example:

    val s = ConcurrentScheduler()
    val task = s.scheduleRepeated(10.seconds, 50.seconds, {
      doSomething()
    })
    
    // later, cancels the scheduling ...
    task.cancel()
    Definition Classes
    execution
  • AssignableCancelable
  • BooleanCancelable
  • CompositeCancelable
  • MultiAssignmentCancelable
  • RefCountCancelable
  • SerialCancelable
  • SingleAssignmentCancelable
  • StackedCancelable
  • package exceptions
    Definition Classes
    execution
  • package internal
    Definition Classes
    execution
  • package misc
    Definition Classes
    execution
  • package rstreams
    Definition Classes
    execution
  • package schedulers
    Definition Classes
    execution
p

monix.execution

cancelables

package cancelables

Cancelables represent asynchronous units of work or other things scheduled for execution and whose execution can be canceled.

One use-case is the scheduling done by monix.execution.Scheduler, in which the scheduling methods return a Cancelable, allowing the canceling of the scheduling.

Example:

val s = ConcurrentScheduler()
val task = s.scheduleRepeated(10.seconds, 50.seconds, {
  doSomething()
})

// later, cancels the scheduling ...
task.cancel()
Source
package.scala
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. cancelables
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. trait AssignableCancelable extends Cancelable

    Represents a class of cancelables that can hold an internal reference to another cancelable (and thus has to support the assignment operator).

    Represents a class of cancelables that can hold an internal reference to another cancelable (and thus has to support the assignment operator).

    Examples are the MultiAssignmentCancelable and the SingleAssignmentCancelable.

    On assignment, if this cancelable is already canceled, then no assignment should happen and the update reference should be canceled as well.

  2. trait BooleanCancelable extends Cancelable

    Represents a Cancelable that can be queried for the canceled status.

  3. final class CompositeCancelable extends BooleanCancelable

    Represents a composite of multiple cancelables.

    Represents a composite of multiple cancelables. In case it is canceled, all contained cancelables will be canceled too, e.g...

    val s = CompositeCancelable()
    
    s += c1
    s += c2
    s += c3
    
    // c1, c2, c3 will also be canceled
    s.cancel()

    Additionally, once canceled, on appending of new cancelable references, those references will automatically get canceled too:

    val s = CompositeCancelable()
    s.cancel()
    
    // c1 gets canceled, because s is already canceled
    s += c1
    // c2 gets canceled, because s is already canceled
    s += c2

    Adding and removing references from this composite is thread-safe.

  4. final class MultiAssignmentCancelable extends Multi

    Represents a monix.execution.Cancelable whose underlying cancelable reference can be swapped for another.

    Represents a monix.execution.Cancelable whose underlying cancelable reference can be swapped for another.

    Example:

    val s = MultiAssignmentCancelable()
    s := c1 // sets the underlying cancelable to c1
    s := c2 // swaps the underlying cancelable to c2
    
    s.cancel() // also cancels c2
    
    s := c3 // also cancels c3, because s is already canceled

    Also see SerialCancelable, which is similar, except that it cancels the old cancelable upon assigning a new cancelable.

  5. final class RefCountCancelable extends BooleanCancelable

    Represents a Cancelable that only executes the canceling logic when all dependent cancelable objects have been canceled.

    Represents a Cancelable that only executes the canceling logic when all dependent cancelable objects have been canceled.

    The given callback gets called after our RefCountCancelable is canceled and after all dependent cancelables have been canceled along with the main cancelable.

    In other words, lets say for example that we have acquired 2 children. In order for the cancelable to get canceled, we need to:

    • cancel both children
    • cancel the main RefCountCancelable

    The implementation is thread-safe and cancellation order doesn't matter.

  6. final class SerialCancelable extends Multi

    Represents a monix.execution.Cancelable whose underlying cancelable can be swapped for another cancelable which causes the previous underlying cancelable to be canceled.

    Represents a monix.execution.Cancelable whose underlying cancelable can be swapped for another cancelable which causes the previous underlying cancelable to be canceled.

    Example:

    val s = SerialCancelable()
    s := c1 // sets the underlying cancelable to c1
    s := c2 // cancels c1 and swaps the underlying cancelable to c2
    
    s.cancel() // also cancels c2
    
    s := c3 // also cancels c3, because s is already canceled

    Also see MultiAssignmentCancelable, which is similar, but doesn't cancel the old cancelable upon assignment.

  7. final class SingleAssignmentCancelable extends Bool

    Represents a monix.execution.Cancelable that can be assigned only once to another cancelable reference.

    Represents a monix.execution.Cancelable that can be assigned only once to another cancelable reference.

    Similar to monix.execution.cancelables.MultiAssignmentCancelable, except that in case of multi-assignment, it throws a java.lang.IllegalStateException.

    If the assignment happens after this cancelable has been canceled, then on assignment the reference will get canceled too.

    Useful in case you need a forward reference.

  8. final class StackedCancelable extends BooleanCancelable

    Represents a composite of cancelables that are stacked, so you can push a new reference, or pop an existing one and when it gets canceled, then the whole stack gets canceled.

    Represents a composite of cancelables that are stacked, so you can push a new reference, or pop an existing one and when it gets canceled, then the whole stack gets canceled.

    Similar in spirit with CompositeCancelable, except that you can only pull out references in a FIFO fashion.

    Used in the implementation of monix.eval.Task.

Inherited from AnyRef

Inherited from Any

Ungrouped