drift/actor

Wraps a pure functional core defined with drift as an OTP actor.

Types

pub opaque type Builder(s, io, i, o, e)

Holds the functions required to run the IO for a drift actor.

pub opaque type IoDriver(state, input, output)

Values

pub fn call(
  actor: process.Subject(message),
  waiting timeout: Int,
  sending make_request: fn(drift.Effect(reply)) -> message,
) -> reply

Similar to process.call, but dispatches to the stepper.

pub fn call_forever(
  actor: process.Subject(message),
  sending make_request: fn(drift.Effect(reply)) -> message,
) -> reply

Similar to process.call_forever, but dispatches to the stepper.

pub fn named(
  builder: Builder(s, io, i, o, e),
  name: process.Name(i),
) -> Builder(s, io, i, o, e)

Configures the actor to use a named process and subject for the inputs. This allows using supervision and not invalidating previous subjects on restarts.

pub fn start(
  builder: Builder(s, io, i, o, e),
  timeout: Int,
  init: fn(process.Subject(i)) -> result,
) -> Result(actor.Started(result), actor.StartError)

Starts the actor with the provided configuration, timeout and possible extra initialization. The extra initialization will happen as part of the actor initialization, and contributes to the timeout limit. If you want to do asynchronous initialization, consider sending a message to another process.

pub fn using_io(
  with_initial_state init: fn() -> state,
  selecting_inputs get_selector: fn(state) -> process.Selector(
    input,
  ),
  handling_outputs_with handle_output: fn(
    drift.EffectContext(state),
    output,
  ) -> Result(drift.EffectContext(state), String),
) -> IoDriver(state, input, output)

Sets up an IoDriver instance, for starting a drift actor. The init function will be called from the actor process, and should return the initial state and input selector. The output handler function gets the effect context and output as arguments, and returns the new effect context or an error. get_selector should extract the Selector for inputs from the io state.

pub fn with_stepper(
  io_driver: IoDriver(io, i, o),
  with_initial_state initial_state: s,
  handling_inputs_with handle_input: fn(drift.Context(i, o), s, i) -> drift.Step(
    s,
    i,
    o,
    e,
  ),
) -> Builder(s, io, i, o, e)

Configures the drift stepper to use with the actor, this is the second mandatory step after configuring the IO, after which other options are optional.

Search Document