Package swim.concurrent

Timer, task, and continuation passing style interfaces, with lightweight scheduler and execution stage implementations.

Timers

A TimerFunction represents a function to invoke at a scheduled time. Scheduling a timer yields a TimerRef, which can be used to check the status of the timer, to reschedule it, and to cancel it. A Timer represents a stateful TimerFunction, with lifecycle callbacks, and a TimerContext that enables self-management.

Tasks

A TaskFunction represents a function to invoke as a sequential process in a concurrent environment. Registering a task yields a TaskRef, which is used to cue the task for execution. A Task represents a stateful TaskFunction, with lifecycle callbacks, and a TaskContext that enables self-management. A Task is like a primitive actor that lacks a builtin mailbox.

Cont

A Cont represents the continuation of an asynchronous operation. Cont has factory functions to construct various Continuation combinators. Sync implements a synchronous Continuation that continues the current thread of execution after an asynchronous operation completes.

Calls

A Call provides a handle used to eventually complete an asynchronous operation by invoking a Continuation. Although a Continuation can be completed directly, by invoking bind(T), or Cont.trap(Throwable), completeing a Continuation through a Call abstracts over the execution context in which the Continuation runs. For example, a Call returned by Stage.call(Cont) invokes its bound Continuation in an asynchronous task, preventing unbounded stack growth from occurring when chaining large numbers of Continuations together.

Schedules

A Schedule arranges for the on-time execution of timers. Clock implements a Schedule algorithm that efficiently scales to large numbers of timers.

Stages

A Stage concurrently executes sequential tasks. Theater implements an execution Stage backed by a ForkJoinPool.