ox

package ox

Members list

Packages

package ox.channels

Type members

Classlikes

trait CancellableFork[T] extends Fork[T]

A fork started using forkCancellable, backed by a (virtual) thread.

A fork started using forkCancellable, backed by a (virtual) thread.

Attributes

Supertypes
trait Fork[T]
class Object
trait Matchable
class Any
class DefaultSupervisor() extends Supervisor

Attributes

Supertypes
trait Supervisor
class Object
trait Matchable
class Any
trait Fork[T]

A fork started using fork, forkDaemon or forkUnsupervised, backed by a (virtual) thread.

A fork started using fork, forkDaemon or forkUnsupervised, backed by a (virtual) thread.

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
trait CancellableFork[T]
class ForkLocal[T](scopedValue: ScopedValue[T], default: T)

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
object ForkLocal

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
ForkLocal.type
object NoOpSupervisor extends Supervisor

Attributes

Supertypes
trait Supervisor
class Object
trait Matchable
class Any
Self type
case class Ox(scope: StructuredTaskScope[Any], finalizers: AtomicReference[List[() => Unit]], supervisor: Supervisor)

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
trait Supervisor

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
object NoOpSupervisor.type
object syntax

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
syntax.type

Value members

Concrete methods

def forever(f: => Unit): Nothing
def fork[T](f: => T)(using Ox): Fork[T]

Starts a fork (logical thread of execution), which is guaranteed to complete before the enclosing supervised or scoped block completes.

Starts a fork (logical thread of execution), which is guaranteed to complete before the enclosing supervised or scoped block completes.

In case an exception is thrown while evaluating t, it will be thrown when calling the returned Fork's .join() method.

If ran in a supervised scope, an exception will cause the enclosing scope to end. Moreover, the scope will end only once all supervised forks (such as this one) complete.

Attributes

def forkAll[T](fs: Seq[() => T])(using Ox): Fork[Seq[T]]
def forkCancellable[T](f: => T)(using Ox): CancellableFork[T]

A cancellable fork is created by starting a nested scope in a fork, and then starting a fork there. Hence, it is more expensive than fork, as two virtual threads are started.

A cancellable fork is created by starting a nested scope in a fork, and then starting a fork there. Hence, it is more expensive than fork, as two virtual threads are started.

Otherwise, works same as forkUnsupervised.

Attributes

def forkDaemon[T](f: => T)(using Ox): Fork[T]

Starts a fork (logical thread of execution), which is guaranteed to complete before the enclosing supervised or scoped block exits.

Starts a fork (logical thread of execution), which is guaranteed to complete before the enclosing supervised or scoped block exits.

In case an exception is thrown while evaluating t, it will be thrown when calling the returned Fork's .join() method.

If ran in a supervised scope, an exception will cause the enclosing scope to end. However, unlike fork, the enclosing scope might end (cancelling this fork) before this fork completes.

If ran in an unsupervised scope, behaves the same as fork.

Attributes

def forkUnsupervised[T](f: => T)(using Ox): Fork[T]

Starts a fork (logical thread of execution), which is guaranteed to complete before the enclosing supervised or scoped block exits.

Starts a fork (logical thread of execution), which is guaranteed to complete before the enclosing supervised or scoped block exits.

In case an exception is thrown while evaluating t, it will be thrown when calling the returned Fork's .join() method.

Success or failure isn't signalled to the supervisor. If ran in an unsupervised scope, behaves the same as fork.

Attributes

def par[T1, T2](t1: => T1)(t2: => T2): (T1, T2)

Runs the given computations in parallel. If any fails, interrupts the others, and re-throws the exception.

Runs the given computations in parallel. If any fails, interrupts the others, and re-throws the exception.

Attributes

def par[T1, T2, T3](t1: => T1)(t2: => T2)(t3: => T3): (T1, T2, T3)

Runs the given computations in parallel. If any fails, interrupts the others, and re-throws the exception.

Runs the given computations in parallel. If any fails, interrupts the others, and re-throws the exception.

Attributes

def par[T](ts: Seq[() => T]): Seq[T]

Runs the given computations in parallel. If any fails, interrupts the others, and re-throws the exception.

Runs the given computations in parallel. If any fails, interrupts the others, and re-throws the exception.

Attributes

def parLimit[T](parallelism: Int)(ts: Seq[() => T]): Seq[T]

Runs the given computations in parallel, with at most parallelism running in parallel at the same time. If any computation fails, interrupts the others, and re-throws the exception.

Runs the given computations in parallel, with at most parallelism running in parallel at the same time. If any computation fails, interrupts the others, and re-throws the exception.

Attributes

def raceResult[T](fs: Seq[() => T]): T

Returns the result of the first computation to complete (either successfully or with an exception).

Returns the result of the first computation to complete (either successfully or with an exception).

Attributes

def raceResult[T](f1: => T)(f2: => T): T

Returns the result of the first computation to complete (either successfully or with an exception).

Returns the result of the first computation to complete (either successfully or with an exception).

Attributes

def raceSuccess[T](fs: Seq[() => T]): T

Returns the result of the first computation to complete successfully, or if all fail - throws the first exception.

Returns the result of the first computation to complete successfully, or if all fail - throws the first exception.

Attributes

def raceSuccess[T](f1: => T)(f2: => T): T

Returns the result of the first computation to complete successfully, or if all fail - throws the first exception.

Returns the result of the first computation to complete successfully, or if all fail - throws the first exception.

Attributes

def repeatUntil(f: => Boolean): Unit

Repeat evaluating f until it evaluates to true.

Repeat evaluating f until it evaluates to true.

Attributes

def repeatWhile(f: => Boolean): Unit

Repeat evaluating f while it evaluates to true.

Repeat evaluating f while it evaluates to true.

Attributes

def retry[T](times: Int, sleep: FiniteDuration)(f: => T): T
def retryEither[E, T](times: Int, sleep: FiniteDuration)(f: => Either[E, T]): Either[E, T]
def scoped[T](f: Ox ?=> T): T

Starts a new scope, which allows starting forks in the given code block f. Forks can be started using fork.

Starts a new scope, which allows starting forks in the given code block f. Forks can be started using fork.

The code is ran in unsupervised mode, that is:

  • the scope ends once the f code block completes; this causes any running forks started within f to be cancelled
  • the scope completes (that is, this method returns) only once all forks started by f have completed (either successfully, or with an exception)
  • fork failures aren't handled in any special way, but can be inspected using Fork.join

Forks created using forkDaemon and forkUnsupervised will behave exactly the same as forks created using fork.

Attributes

See also

supervised Starts a scope in supervised mode

def supervised[T](f: Ox ?=> T): T

Starts a new scope, which allows starting forks in the given code block f. Forks can be started using fork, forkDaemon and forkUnsupervised.

Starts a new scope, which allows starting forks in the given code block f. Forks can be started using fork, forkDaemon and forkUnsupervised.

The code is ran in supervised mode, that is:

  • the scope ends once all non-daemon, supervised forks (including the f code block) succeed
  • the scope also ends once the first supervised fork (including the f code block) fails with an exception
  • when the scope ends, all running forks are cancelled
  • the scope completes (that is, this method returns) only once all forks started by f have completed (either successfully, or with an exception)

Attributes

See also

scoped Starts a scope in unsupervised mode

def supervisor[T](supervisor: Supervisor)(f: Ox ?=> T)(using Ox): T

Change the supervisor that is being used when running f. Doesn't affect existing usages of the current supervisor, or forks ran outside of f.

Change the supervisor that is being used when running f. Doesn't affect existing usages of the current supervisor, or forks ran outside of f.

Attributes

def timeout[T](duration: FiniteDuration)(t: => T): T

The result of computation t, if it took less than duration, and a TimeoutException otherwise.

The result of computation t, if it took less than duration, and a TimeoutException otherwise.

Attributes

Throws
TimeoutException

If t took more than duration.

def timeoutOption[T](duration: FiniteDuration)(t: => T): Option[T]

A Some if the computation t took less than duration, and None otherwise.

A Some if the computation t took less than duration, and None otherwise.

Attributes

def uninterruptible[T](f: => T): T
def useCloseableInScope[T <: AutoCloseable](c: => T)(using Ox): T
def useInScope[T](acquire: => T)(release: T => Unit)(using Ox): T

Use the given resource in the current scope. The resource is allocated using acquire, and released after the scope is done using release. Releasing is uninterruptible.

Use the given resource in the current scope. The resource is allocated using acquire, and released after the scope is done using release. Releasing is uninterruptible.

Attributes

def useScoped[T, U](acquire: => T)(release: T => Unit)(b: T => U): U
def useScoped[T <: AutoCloseable, U](acquire: => T)(b: T => U): U
def useSupervised[T, U](acquire: => T)(release: T => Unit)(b: T => U): U
def useSupervised[T <: AutoCloseable, U](acquire: => T)(b: T => U): U