ox

package ox

Members list

Packages

package ox.channels
package ox.resilience
package ox.scheduling

Type members

Classlikes

final case class ArrayChunk[A](array: Array[A]) extends Chunk[A]

Attributes

Supertypes
trait Serializable
trait Product
class Chunk[A]
trait IndexedSeq[A]
trait IndexedSeqOps[A, IndexedSeq, IndexedSeq[A]]
trait IndexedSeq[A]
trait IndexedSeqOps[A, IndexedSeq, IndexedSeq[A]]
trait Seq[A]
trait SeqOps[A, IndexedSeq, IndexedSeq[A]]
trait Seq[A]
trait Equals
trait SeqOps[A, IndexedSeq, IndexedSeq[A]]
trait PartialFunction[Int, A]
trait Int => A
trait Iterable[A]
trait Iterable[A]
trait IterableFactoryDefaults[A, IndexedSeq]
trait IterableOps[A, IndexedSeq, IndexedSeq[A]]
trait IterableOnceOps[A, IndexedSeq, IndexedSeq[A]]
trait IterableOnce[A]
class Object
trait Matchable
class Any
Show all
trait CancellableFork[T] extends UnsupervisedFork[T]

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

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

Attributes

Supertypes
trait UnsupervisedFork[T]
trait Fork[T]
class Object
trait Matchable
class Any
sealed abstract class Chunk[+A] extends IndexedSeq[A]

An immutable finite indexed sequence of elements, backed by Array. Currently represents only a think wrapper, delegating all operations from IndexedSeq directly to underlying Array equivalents. Such operations can be expensive when you want to do concatenation, splitAt, drop, etc. - transformations that are often useful when doing Source processing. Chunk should therefore evolve towards a performance-optimized, underneath leveraging Arrays wrapped with lazy data structures to avoid unnecessary data copying.

An immutable finite indexed sequence of elements, backed by Array. Currently represents only a think wrapper, delegating all operations from IndexedSeq directly to underlying Array equivalents. Such operations can be expensive when you want to do concatenation, splitAt, drop, etc. - transformations that are often useful when doing Source processing. Chunk should therefore evolve towards a performance-optimized, underneath leveraging Arrays wrapped with lazy data structures to avoid unnecessary data copying.

Attributes

Companion
object
Supertypes
trait IndexedSeq[A]
trait IndexedSeqOps[A, IndexedSeq, IndexedSeq[A]]
trait IndexedSeq[A]
trait IndexedSeqOps[A, IndexedSeq, IndexedSeq[A]]
trait Seq[A]
trait SeqOps[A, IndexedSeq, IndexedSeq[A]]
trait Seq[A]
trait Equals
trait SeqOps[A, IndexedSeq, IndexedSeq[A]]
trait PartialFunction[Int, A]
trait Int => A
trait Iterable[A]
trait Iterable[A]
trait IterableFactoryDefaults[A, IndexedSeq]
trait IterableOps[A, IndexedSeq, IndexedSeq[A]]
trait IterableOnceOps[A, IndexedSeq, IndexedSeq[A]]
trait IterableOnce[A]
class Object
trait Matchable
class Any
Show all
Known subtypes
class ArrayChunk[A]
object Empty
object Chunk

Attributes

Companion
class
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
Chunk.type
class EitherMode[E] extends ErrorMode[E, [T] =>> Either[E, T]]

An error mode where errors are represented as Either[E, T] instances.

An error mode where errors are represented as Either[E, T] instances.

Attributes

Supertypes
trait ErrorMode[E, [T] =>> Either[E, T]]
class Object
trait Matchable
class Any
case object Empty extends Chunk[Nothing]

Attributes

Supertypes
trait Singleton
trait Product
trait Mirror
trait Serializable
trait Product
class Chunk[Nothing]
trait IndexedSeq[Nothing]
trait IndexedSeqOps[Nothing, IndexedSeq, IndexedSeq[Nothing]]
trait IndexedSeq[Nothing]
trait IndexedSeqOps[Nothing, IndexedSeq, IndexedSeq[Nothing]]
trait Seq[Nothing]
trait SeqOps[Nothing, IndexedSeq, IndexedSeq[Nothing]]
trait Seq[Nothing]
trait Equals
trait SeqOps[Nothing, IndexedSeq, IndexedSeq[Nothing]]
trait PartialFunction[Int, Nothing]
trait Int => Nothing
trait Iterable[Nothing]
trait Iterable[Nothing]
trait IterableFactoryDefaults[Nothing, IndexedSeq]
trait IterableOps[Nothing, IndexedSeq, IndexedSeq[Nothing]]
trait IterableOnceOps[Nothing, IndexedSeq, IndexedSeq[Nothing]]
trait IterableOnce[Nothing]
class Object
trait Matchable
class Any
Show all
Self type
Empty.type
trait ErrorMode[E, F[_]]

Describes the representation of application errors. Such errors have type E and are reported in context F.

Describes the representation of application errors. Such errors have type E and are reported in context F.

An application error is a value which is returned as a successful completion of a fork. However, unlike regular values, such error values are reported and cause the enclosing scope to end.

For any type T, F[T] represents a value which might either:

  • be successful; in that case, a T instance can be derived
  • be an error; in that case, an E instance can be derived

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
class EitherMode[E]
object NoErrorMode
class UnionMode[E]
enum ExitCode(val code: Int)

Attributes

Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
Known subtypes
case Failure
trait Fork[T]

A fork started using fork, forkError, forkUser, forkUserError, forkCancellable or forkUnsupervised, backed by a (virtual) thread.

A fork started using fork, forkError, forkUser, forkUserError, forkCancellable or forkUnsupervised, backed by a (virtual) thread.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
trait UnsupervisedFork[T]
trait CancellableFork[T]
object Fork

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
Fork.type
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 NoErrorMode extends ErrorMode[Nothing, [T] =>> T]

An error mode which doesn't allow reporting application errors.

An error mode which doesn't allow reporting application errors.

However, forks can still fail by throwing exceptions.

Attributes

Supertypes
trait ErrorMode[Nothing, [T] =>> T]
class Object
trait Matchable
class Any
Self type
trait Ox extends OxUnsupervised

Capability granted by an supervised or supervisedError concurrency scope.

Capability granted by an supervised or supervisedError concurrency scope.

Represents a capability to:

  • fork supervised or unsupervised, asynchronously running computations in a concurrency scope. Such forks can be created using fork, forkUser, forkUnsupervised or forkCancellable.
  • register resources to be cleaned up after the scope ends

Attributes

See also
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class OxError[E, F]
trait OxApp

Extend this trait when defining application entry points. Comes in several variants:

Extend this trait when defining application entry points. Comes in several variants:

The benefit of using OxApp compared to normal @main methods is that application interruptions is handled properly. A fork in a scope is created to run the application's logic. Interrupting the application (by sending SIGINT/SIGTERM, e.g. using CTRL+C) will cause the scope to end and all forks to be interrupted, allowing for a clean shutdown.

That way, any resources that have been allocated and attached to scopes, or that are managed using try-finally blocks inside forks, will be released properly.

Certain aspects of exception handling can be configured using OxApp.Settings and overriding the settings method.

The application's code is specified in a run method, which has the Ox capability granted: to fork asynchronously computations, and register clean up of resources

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
trait Simple
trait WithErrorMode[E, F]
class WithEitherErrors[E]
object OxApp

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
OxApp.type
case class OxError[E, F[_]](scope: StructuredTaskScope[Any], finalizers: AtomicReference[List[() => Unit]], supervisor: Supervisor[E], errorMode: ErrorMode[E, F]) extends Ox

Capability granted by a supervisedError concurrency scope.

Capability granted by a supervisedError concurrency scope.

Represents a capability to:

OxError is similar to Ox, however it additionally allows completing forks with application errors of type E in context F. Such errors cause enclosing scope to end, and any forks that are still running to be cancelled

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
trait Ox
class Object
trait Matchable
class Any
Show all
object OxError

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
OxError.type

Capability granted by an unsupervised concurrency scope (as well as, via subtyping, by supervised and supervisedError).

Capability granted by an unsupervised concurrency scope (as well as, via subtyping, by supervised and supervisedError).

Represents a capability to:

  • fork unsupervised, asynchronously running computations in a concurrency scope. Such forks can be created using forkUnsupervised or forkCancellable.
  • register resources to be cleaned up after the scope ends

Attributes

See also
Supertypes
class Object
trait Matchable
class Any
Known subtypes
trait Ox
class OxError[E, F]
case class SecondaryApplicationError[E](e: E) extends Throwable

Attributes

Supertypes
trait Product
trait Equals
class Throwable
trait Serializable
class Object
trait Matchable
class Any
Show all
class UnionMode[E] extends ErrorMode[E, [T] =>> E | T]

An error mode where errors are represented as an union of E and T values. T should always be different from E, otherwise errors can't be told apart from successful values. To discern between the two, a class tag for E is necessary (it must have a distinct run-time representation).

An error mode where errors are represented as an union of E and T values. T should always be different from E, otherwise errors can't be told apart from successful values. To discern between the two, a class tag for E is necessary (it must have a distinct run-time representation).

Attributes

Supertypes
trait ErrorMode[E, [T] =>> E | T]
class Object
trait Matchable
class Any
trait UnsupervisedFork[T] extends Fork[T]

Attributes

Companion
object
Supertypes
trait Fork[T]
class Object
trait Matchable
class Any
Known subtypes
trait CancellableFork[T]

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
object either

Attributes

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

Value members

Concrete methods

inline def checkInterrupt(): Unit

Checks if the current thread is interrupted. Useful in compute-intensive code, which wants to cooperate in the cancellation protocol, e.g. when run in a supervised scope.

Checks if the current thread is interrupted. Useful in compute-intensive code, which wants to cooperate in the cancellation protocol, e.g. when run in a supervised scope.

Attributes

Throws
InterruptedException

if the current thread is interrupted.

inline def forever(inline f: Unit): Nothing

Repeat evaluating f forever.

Repeat evaluating f forever.

Attributes

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 supervisedError block completes.

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

The fork behaves as a daemon thread. That is, if the body of the scope completes successfully, and all other user forks (created using forkUser) complete successfully, the scope will end, cancelling all running forks (including this one, if it's still running). That is, successful completion of this fork isn't required to end the scope.

An exception thrown while evaluating t will cause the fork to fail and the enclosing scope to end (cancelling all other running forks).

For alternate behaviors regarding ending the scope, see forkUser, forkError, forkUserError, forkCancellable and forkUnsupervised.

Attributes

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

For each thunk in the given sequence, starts a fork using fork. All forks are guaranteed to complete before the enclosing supervised or unsupervised block completes.

For each thunk in the given sequence, starts a fork using fork. All forks are guaranteed to complete before the enclosing supervised or unsupervised block completes.

If ran in a supervised scope, all forks behave as daemon threads (see fork for details).

Attributes

def forkCancellable[T](f: => T)(using OxUnsupervised): CancellableFork[T]

Starts a fork (logical thread of execution), which is guaranteed to complete before the enclosing supervised, supervisedError or unsupervised block completes, and which can be cancelled on-demand.

Starts a fork (logical thread of execution), which is guaranteed to complete before the enclosing supervised, supervisedError or unsupervised block completes, and which can be cancelled on-demand.

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

The fork is unsupervised (similarly to forkUnsupervised), hence success or failure isn't signalled to the enclosing scope and doesn't influence the scope's lifecycle.

For alternate behaviors, see fork, forkError, forkUser, forkUserError and forkUnsupervised.

Implementation note: 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.

Attributes

def forkError[E, F[_], T](using OxError[E, F])(f: => F[T]): Fork[T]

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

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

Behaves the same as fork, but additionally allows reporting application errors represented as values of type E in context F. An application error causes the enclosing scope to end.

Application errors are values with which forks might successfully complete, but are still considered a value-level representation of an error (as opposed to an exception, which isn't a value which is returned, but is thrown instead). Such errors are reported to the enclosing scope. If the ErrorMode provided when creating the scope using supervisedError classifies a fork return value as an error, the scope ends (cancelling all other running forks).

Attributes

def forkUnsupervised[T](f: => T)(using OxUnsupervised): UnsupervisedFork[T]

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

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

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

Success or failure isn't signalled to the enclosing scope, and doesn't influence the scope's lifecycle.

For alternate behaviors, see fork, forkUser and forkCancellable.

Attributes

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

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

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

The fork behaves as a user-level thread. That is, the scope won't end until the body of the scope, and all other user forks (including this one) complete successfully. That is, successful completion of this fork is required to end the scope.

An exception thrown while evaluating t will cause the enclosing scope to end (cancelling all other running forks).

For alternate behaviors, see fork, forkError, forkUserError, forkCancellable and forkUnsupervised.

Attributes

def forkUserError[E, F[_], T](using OxError[E, F])(f: => F[T]): Fork[T]

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

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

Behaves the same as forkUser, but additionally allows reporting application errors represented as values of type E in context F, which cause the enclosing scope to end.

Application errors are values with which forks might successfully complete, but are still considered a value-level representation of an error (as opposed to an exception, which isn't a value which is returned, but is thrown instead). Such errors are reported to the enclosing scope. If the ErrorMode provided when creating the scope using supervisedError classifies a fork return value as an error, the scope ends (cancelling all other running forks).

Attributes

inline def never: Nothing

Blocks the current thread indefinitely, until it is interrupted.

Blocks the current thread indefinitely, until it is interrupted.

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[T1, T2, T3, T4](t1: => T1, t2: => T2, t3: => T3, t4: => T4): (T1, T2, T3, T4)

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 par[E, F[_], T1, T2](em: ErrorMode[E, F])(t1: => F[T1], t2: => F[T2]): F[(T1, T2)]

Runs the given computations in parallel. If any fails because of an exception, or if any returns an application error, other computations are interrupted. Then, the exception is re-thrown, or the error value returned. Application errors must be of type E in context F, and each computation must return an F-wrapped value.

Runs the given computations in parallel. If any fails because of an exception, or if any returns an application error, other computations are interrupted. Then, the exception is re-thrown, or the error value returned. Application errors must be of type E in context F, and each computation must return an F-wrapped value.

Attributes

def par[E, F[_], T1, T2, T3](em: ErrorMode[E, F])(t1: => F[T1], t2: => F[T2], t3: => F[T3]): F[(T1, T2, T3)]

Runs the given computations in parallel. If any fails because of an exception, or if any returns an application error, other computations are interrupted. Then, the exception is re-thrown, or the error value returned. Application errors must be of type E in context F, and each computation must return an F-wrapped value.

Runs the given computations in parallel. If any fails because of an exception, or if any returns an application error, other computations are interrupted. Then, the exception is re-thrown, or the error value returned. Application errors must be of type E in context F, and each computation must return an F-wrapped value.

Attributes

def par[E, F[_], T1, T2, T3, T4](em: ErrorMode[E, F])(t1: => F[T1], t2: => F[T2], t3: => F[T3], t4: => F[T4]): F[(T1, T2, T3, T4)]

Runs the given computations in parallel. If any fails because of an exception, or if any returns an application error, other computations are interrupted. Then, the exception is re-thrown, or the error value returned. Application errors must be of type E in context F, and each computation must return an F-wrapped value.

Runs the given computations in parallel. If any fails because of an exception, or if any returns an application error, other computations are interrupted. Then, the exception is re-thrown, or the error value returned. Application errors must be of type E in context F, and each computation must return an F-wrapped value.

Attributes

def par[E, F[_], T](em: ErrorMode[E, F])(ts: Seq[() => F[T]]): F[Seq[T]]

Runs the given computations in parallel. If any fails because of an exception, or if any returns an application error, other computations are interrupted. Then, the exception is re-thrown, or the error value returned. Application errors must be of type E in context F, and each computation must return an F-wrapped value.

Runs the given computations in parallel. If any fails because of an exception, or if any returns an application error, other computations are interrupted. Then, the exception is re-thrown, or the error value returned. Application errors must be of type E in context F, and each computation must return an F-wrapped value.

Attributes

def parEither[E, T1, T2](t1: => Either[E, T1], t2: => Either[E, T2]): Either[E, (T1, T2)]

Runs the given computations in parallel. If any fails because of an exception, or if any returns a Left, other computations are interrupted. Then, the exception is re-thrown, or the Left error value returned. Each computation must return an Either, with an error type being a subtype of E.

Runs the given computations in parallel. If any fails because of an exception, or if any returns a Left, other computations are interrupted. Then, the exception is re-thrown, or the Left error value returned. Each computation must return an Either, with an error type being a subtype of E.

Attributes

def parEither[E, T1, T2, T3](t1: => Either[E, T1], t2: => Either[E, T3], t3: => Either[E, T3]): Either[E, (T1, T2, T3)]

Runs the given computations in parallel. If any fails because of an exception, or if any returns a Left, other computations are interrupted. Then, the exception is re-thrown, or the Left error value returned. Each computation must return an Either, with an error type being a subtype of E.

Runs the given computations in parallel. If any fails because of an exception, or if any returns a Left, other computations are interrupted. Then, the exception is re-thrown, or the Left error value returned. Each computation must return an Either, with an error type being a subtype of E.

Attributes

def parEither[E, T1, T2, T3, T4](t1: => Either[E, T1], t2: => Either[E, T3], t3: => Either[E, T3], t4: => Either[E, T4]): Either[E, (T1, T2, T3, T4)]

Runs the given computations in parallel. If any fails because of an exception, or if any returns a Left, other computations are interrupted. Then, the exception is re-thrown, or the Left error value returned. Each computation must return an Either, with an error type being a subtype of E.

Runs the given computations in parallel. If any fails because of an exception, or if any returns a Left, other computations are interrupted. Then, the exception is re-thrown, or the Left error value returned. Each computation must return an Either, with an error type being a subtype of E.

Attributes

def parEither[E, T](ts: Seq[() => Either[E, T]]): Either[E, Seq[T]]

Runs the given computations in parallel. If any fails because of an exception, or if any returns a Left, other computations are interrupted. Then, the exception is re-thrown, or the Left error value returned. Each computation must return an Either, with an error type being a subtype of E.

Runs the given computations in parallel. If any fails because of an exception, or if any returns a Left, other computations are interrupted. Then, the exception is re-thrown, or the Left error value returned. Each computation must return an Either, with an error type being a subtype of E.

Attributes

def parEitherLimit[E, T](parallelism: Int)(ts: Seq[() => Either[E, T]]): Either[E, Seq[T]]

Runs the given computations in parallel, with at most parallelism running in parallel at the same time. If any computation fails because of an exception, or if any returns a Left, other computations are interrupted. Then, the exception is re-thrown, or the Left error value returned. Each computation must return an Either, with an error type being a subtype of E.

Runs the given computations in parallel, with at most parallelism running in parallel at the same time. If any computation fails because of an exception, or if any returns a Left, other computations are interrupted. Then, the exception is re-thrown, or the Left error value returned. Each computation must return an Either, with an error type being a subtype of E.

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 parLimit[E, F[_], T](em: ErrorMode[E, F])(parallelism: Int)(ts: Seq[() => F[T]]): F[Seq[T]]

Runs the given computations in parallel, with at most parallelism running in parallel at the same time. If any computation fails because of an exception, or if any returns an application error, other computations are interrupted. Then, the exception is re-thrown, or the error value returned. Application errors must be of type E in context F, and each computation must return an F-wrapped value.

Runs the given computations in parallel, with at most parallelism running in parallel at the same time. If any computation fails because of an exception, or if any returns an application error, other computations are interrupted. Then, the exception is re-thrown, or the error value returned. Application errors must be of type E in context F, and each computation must return an F-wrapped value.

Attributes

def race[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 race[E, F[_], T](em: ErrorMode[E, F])(fs: Seq[() => F[T]]): F[T]

Returns the result of the first computation to complete successfully, or if all fail / return an application error - throws the first exception / returns the first application error. Application errors must be of type E in context F, and each computation must return an F-wrapped value.

Returns the result of the first computation to complete successfully, or if all fail / return an application error - throws the first exception / returns the first application error. Application errors must be of type E in context F, and each computation must return an F-wrapped value.

Attributes

def race[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 race[T](f1: => T, f2: => T, f3: => 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 race[T](f1: => T, f2: => T, f3: => T, f4: => 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 race[E, F[_], T](em: ErrorMode[E, F])(f1: => F[T], f2: => F[T]): F[T]

Returns the result of the first computation to complete successfully, or if all fail / return an application error - throws the first exception / returns the first application error. Application errors must be of type E in context F, and each computation must return an F-wrapped value.

Returns the result of the first computation to complete successfully, or if all fail / return an application error - throws the first exception / returns the first application error. Application errors must be of type E in context F, and each computation must return an F-wrapped value.

Attributes

def race[E, F[_], T](em: ErrorMode[E, F])(f1: => F[T], f2: => F[T], f3: => F[T]): F[T]

Returns the result of the first computation to complete successfully, or if all fail / return an application error - throws the first exception / returns the first application error. Application errors must be of type E in context F, and each computation must return an F-wrapped value.

Returns the result of the first computation to complete successfully, or if all fail / return an application error - throws the first exception / returns the first application error. Application errors must be of type E in context F, and each computation must return an F-wrapped value.

Attributes

def race[E, F[_], T](em: ErrorMode[E, F])(f1: => F[T], f2: => F[T], f3: => F[T], f4: => F[T]): F[T]

Returns the result of the first computation to complete successfully, or if all fail / return an application error - throws the first exception / returns the first application error. Application errors must be of type E in context F, and each computation must return an F-wrapped value.

Returns the result of the first computation to complete successfully, or if all fail / return an application error - throws the first exception / returns the first application error. Application errors must be of type E in context F, and each computation must return an F-wrapped value.

Attributes

def raceEither[E, T](f1: => Either[E, T], f2: => Either[E, T]): Either[E, T]

Returns the result of the first computation to complete successfully, or if all fail / return a Left - throws the first exception / returns the first Left. Each computation must return an Either, with an error type being a subtype of E.

Returns the result of the first computation to complete successfully, or if all fail / return a Left - throws the first exception / returns the first Left. Each computation must return an Either, with an error type being a subtype of E.

Attributes

def raceEither[E, T](f1: => Either[E, T], f2: => Either[E, T], f3: => Either[E, T]): Either[E, T]

Returns the result of the first computation to complete successfully, or if all fail / return a Left - throws the first exception / returns the first Left. Each computation must return an Either, with an error type being a subtype of E.

Returns the result of the first computation to complete successfully, or if all fail / return a Left - throws the first exception / returns the first Left. Each computation must return an Either, with an error type being a subtype of E.

Attributes

def raceEither[E, T](f1: => Either[E, T], f2: => Either[E, T], f3: => Either[E, T], f4: => Either[E, T]): Either[E, T]

Returns the result of the first computation to complete successfully, or if all fail / return a Left - throws the first exception / returns the first Left. Each computation must return an Either, with an error type being a subtype of E.

Returns the result of the first computation to complete successfully, or if all fail / return a Left - throws the first exception / returns the first Left. Each computation must return an Either, with an error type being a subtype of E.

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 raceResult[T](f1: => T, f2: => T, f3: => 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, f3: => T, f4: => 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 releaseAfterScope(release: => Unit)(using OxUnsupervised): Unit

Release the given resource, by running the release code block. Releasing is done after all the forks in the scope complete (either successfully or with an error), but before the current concurrency scope completes. Releasing is uninterruptible.

Release the given resource, by running the release code block. Releasing is done after all the forks in the scope complete (either successfully or with an error), but before the current concurrency scope completes. Releasing is uninterruptible.

Attributes

def releaseCloseableAfterScope(toRelease: AutoCloseable)(using OxUnsupervised): Unit

Release the given resource, which implements AutoCloseable, by running its .close() method. Releasing is done after all the forks in the scope complete (either successfully or with an error), but before the current concurrency scope completes. Releasing is uninterruptible.

Release the given resource, which implements AutoCloseable, by running its .close() method. Releasing is done after all the forks in the scope complete (either successfully or with an error), but before the current concurrency scope completes. Releasing is uninterruptible.

Attributes

inline def repeatUntil(inline f: Boolean): Unit

Repeat evaluating f until it evaluates to true.

Repeat evaluating f until it evaluates to true.

Attributes

inline def repeatWhile(inline f: Boolean): Unit

Repeat evaluating f while it evaluates to true.

Repeat evaluating f while it evaluates to true.

Attributes

inline def sleep(inline howLong: Duration): Unit

Sleep (block the current thread/fork) for the provided amount of time.

Sleep (block the current thread/fork) for the provided amount of time.

Attributes

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

Starts a new concurrency scope, which allows starting forks in the given code block f. Forks can be started using fork, forkUser, forkCancellable and forkUnsupervised. All forks are guaranteed to complete before this scope completes.

Starts a new concurrency scope, which allows starting forks in the given code block f. Forks can be started using fork, forkUser, forkCancellable and forkUnsupervised. All forks are guaranteed to complete before this scope completes.

The scope is ran in supervised mode, that is:

  • the scope ends once all user, supervised forks (started using forkUser), including the f body, succeed. Forks started using fork (daemon) don't have to complete successfully for the scope to end.
  • the scope also ends once the first supervised fork (including the f main body) 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)

Upon successful completion, returns the result of evaluating f. Upon failure, the exception that caused the scope to end is re-thrown (regardless if the exception was thrown from the main body, or from a fork). Any other exceptions that occur when completing the scope are added as suppressed.

Attributes

See also

unsupervised Starts a scope in unsupervised mode

supervisedError Starts a scope in supervised mode, with the additional ability to report application errors

def supervisedError[E, F[_], T](em: ErrorMode[E, F])(f: (OxError[E, F]) ?=> F[T]): F[T]

Starts a new concurrency scope, which allows starting forks in the given code block f. Forks can be started using fork, forkError, forkUser, forkUserError, forkCancellable and forkUnsupervised. All forks are guaranteed to complete before this scope completes.

Starts a new concurrency scope, which allows starting forks in the given code block f. Forks can be started using fork, forkError, forkUser, forkUserError, forkCancellable and forkUnsupervised. All forks are guaranteed to complete before this scope completes.

Behaves the same as supervised, but additionally allows reporting application errors represented as values of type E in context F. An application error causes the enclosing scope to end.

Attributes

See also

forkError On details how to use application errors.

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

The result of computation t, if it took less than duration, and a TimeoutException otherwise. if the computation t throws an exception, it is propagated.

The result of computation t, if it took less than duration, and a TimeoutException otherwise. if the computation t throws an exception, it is propagated.

Attributes

Throws
TimeoutException

If t took more than duration.

def timeoutEither[E, T](duration: FiniteDuration, timeoutValue: E)(t: => Either[E, T]): Either[E, T]

Result of the computation t if it took less than duration, and Left(timeoutValue) otherwise. if the computation t throws an exception, it is propagated.

Result of the computation t if it took less than duration, and Left(timeoutValue) otherwise. if the computation t throws an exception, it is propagated.

Attributes

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

A Some if the computation t took less than duration, and None otherwise. if the computation t throws an exception, it is propagated.

A Some if the computation t took less than duration, and None otherwise. if the computation t throws an exception, it is propagated.

Attributes

inline def uninterruptible[T](inline f: T): T

Prevent f from being interrupted. Any interrupted exceptions that occur while evaluating f will be re-thrown once it completes.

Prevent f from being interrupted. Any interrupted exceptions that occur while evaluating f will be re-thrown once it completes.

Attributes

def unsupervised[T](f: OxUnsupervised ?=> T): T

Starts a new concurrency scope, which allows starting forks in the given code block f. Forks can be started using forkUnsupervised, and forkCancellable. All forks are guaranteed to complete before this scope completes.

Starts a new concurrency scope, which allows starting forks in the given code block f. Forks can be started using forkUnsupervised, and forkCancellable. All forks are guaranteed to complete before this scope completes.

It is advisable to use supervised scopes if possible, as they minimise the chances of an error to go unnoticed.

The scope is ran in unsupervised mode, that is:

  • the scope ends once the f body 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

Upon successful completion, returns the result of evaluating f. Upon failure, that is an exception thrown by f, it is re-thrown.

Attributes

See also

supervised Starts a scope in supervised mode

inline def use[R, T](inline acquire: R, inline release: R => Unit)(inline f: R => T): T

Use the given resource, acquired using acquire and released using release in the given f code block. Releasing is uninterruptible. To use multiple resource, consider created a supervised scope and useInScope method.

Use the given resource, acquired using acquire and released using release in the given f code block. Releasing is uninterruptible. To use multiple resource, consider created a supervised scope and useInScope method.

Attributes

inline def useCloseable[R <: AutoCloseable, T](inline acquire: R)(inline f: R => T): T

Use the given AutoCloseable resource, acquired using acquire in the given f code block. Releasing is uninterruptible. To use multiple resource, consider created a supervised scope and useCloseableInScope method.

Use the given AutoCloseable resource, acquired using acquire in the given f code block. Releasing is uninterruptible. To use multiple resource, consider created a supervised scope and useCloseableInScope method.

Attributes

def useCloseableInScope[T <: AutoCloseable](c: => T)(using OxUnsupervised): T

Use the given resource, which implements AutoCloseable, in the current concurrency scope. The resource is allocated using acquire, and released after the all forks in the scope complete (either successfully or with an error), using AutoCloseable.close(). Releasing is uninterruptible.

Use the given resource, which implements AutoCloseable, in the current concurrency scope. The resource is allocated using acquire, and released after the all forks in the scope complete (either successfully or with an error), using AutoCloseable.close(). Releasing is uninterruptible.

Attributes

def useInScope[T](acquire: => T)(release: T => Unit)(using OxUnsupervised): T

Use the given resource in the current concurrency scope. The resource is allocated using acquire, and released after the all forks in the scope complete (either successfully or with an error), using release. Releasing is uninterruptible.

Use the given resource in the current concurrency scope. The resource is allocated using acquire, and released after the all forks in the scope complete (either successfully or with an error), using release. Releasing is uninterruptible.

Attributes

Extensions

Extensions

extension [T](inline f: Future[T])
inline def get(): T

Block the current thread/fork until the future completes. Returns the successful value of the future, or throws the exception, with which it failed.

Block the current thread/fork until the future completes. Returns the successful value of the future, or throws the exception, with which it failed.

Attributes

extension [I, C <: (Iterable)](iterable: C[I])
def collectPar[O](parallelism: Int)(pf: PartialFunction[I, O]): C[O]

Runs partial function in parallel on each element of iterable for which the partial function is defined. If function is not defined for an element such element is skipped. Using not more than parallelism forks concurrently.

Runs partial function in parallel on each element of iterable for which the partial function is defined. If function is not defined for an element such element is skipped. Using not more than parallelism forks concurrently.

Type parameters

O

type of elements of result

Value parameters

parallelism

maximum number of concurrent forks

pf

partial function to apply to those elements of iterable for which it is defined

Attributes

Returns

collection of results of applying pf to elements of iterable for which it is defined. The returned collection is of the same type as iterable

def filterPar(parallelism: Int)(predicate: I => Boolean): C[I]

Runs predicate in parallel on each element of iterable. Elements for which predicate returns true are returned in the same order as in iterable. Elements for which predicate returns false are skipped. Using not more than parallelism forks concurrently.

Runs predicate in parallel on each element of iterable. Elements for which predicate returns true are returned in the same order as in iterable. Elements for which predicate returns false are skipped. Using not more than parallelism forks concurrently.

Value parameters

parallelism

maximum number of concurrent forks

predicate

predicate to run on each element of iterable

Attributes

Returns

filtered collection

def foreachPar(parallelism: Int)(operation: I => Any): Unit

Parallelize a foreach operation. Runs the operation on each element of the iterable in parallel. Using not more than parallelism forks concurrently.

Parallelize a foreach operation. Runs the operation on each element of the iterable in parallel. Using not more than parallelism forks concurrently.

Value parameters

operation

the operation to perform on each element

parallelism

the number of threads to use

Attributes

def mapPar[O](parallelism: Int)(transform: I => O): C[O]

Runs parallel transformations on iterable. Using not more than parallelism forks concurrently.

Runs parallel transformations on iterable. Using not more than parallelism forks concurrently.

Type parameters

O

type of elements in result

Value parameters

parallelism

maximum number of concurrent forks

transform

transformation to apply to each element of iterable

Attributes

Returns

transformed collection of the same type as input one

extension [T](inline t: T)
inline def discard: Unit

Discard the result of the computation, to avoid discarded non-unit value warnings.

Discard the result of the computation, to avoid discarded non-unit value warnings.

Attributes

Example
 import ox.discard
 someMethodCall().another().discard
inline def pipe[U](inline f: T => U): U

Pipe the value of this expression into the provided function, returning the result of the function. Useful for chaining operations.

Pipe the value of this expression into the provided function, returning the result of the function. Useful for chaining operations.

Value parameters

f

The function to apply to the value of this expression.

Attributes

Returns

The result of applying f to the value of this expression.

See also

scala.util.ChainingOps.pipe for a non-inline version in the standard library

Example
 import ox.pipe
 someMethodCall().pipe { result => transform(result) }
inline def tap(inline f: T => Unit): T

Apply f to the value of this expression, returning the original value of the expression. Useful for side-effecting operations.

Apply f to the value of this expression, returning the original value of the expression. Useful for side-effecting operations.

Value parameters

f

The function to apply to the value of this expression.

Attributes

Returns

The original value of this expression.

See also

scala.util.ChainingOps.tap for a non-inline version in the standard library

Example
 import ox.tap
 someMethodCall().tap { result => log(result) }
inline def tapException(inline f: Throwable => Unit): T

Run the provided callback when an exception occurs, rethrowing the original one after the callback completes.

Run the provided callback when an exception occurs, rethrowing the original one after the callback completes.

If f itself throws an exception, this other exception will be added as suppressed to the original one.

Attributes

Example
 import ox.tapException
 someMethodCall().tapException { e => logger.error("Exception occurred", e) }
inline def tapNonFatalException(inline f: Throwable => Unit): T

Same as tapException, but runs the callback only for non-fatal exceptions.

Same as tapException, but runs the callback only for non-fatal exceptions.

Attributes