drift/actor

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

Types

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

pub opaque type IoDriver(state, input, output)

The message type of the wrapping actor. Should not be directly used, but must be public for supporting actor builders.

pub opaque type Msg(i)

The state of the wrapping actor. Should not be directly used, but must be public for supporting actor builders.

pub opaque type State(state, io, input, output, error)

Values

pub fn builder(
  io_driver: IoDriver(io, i, o),
  timeout: Int,
  state: s,
  handle_input: fn(drift.Context(i, o), s, i) -> drift.Step(
    s,
    i,
    o,
    e,
  ),
  report_to: option.Option(process.Subject(r)),
  make_report: fn(process.Subject(i)) -> r,
) -> actor.Builder(
  State(s, io, i, o, e),
  Msg(i),
  process.Subject(i),
)

Behaves like start, except that it provides an actor builder that allows more configurability for advanced use cases, like supervision. NOTE: Do not reconfigure on_message!

If provided, report_to will be sent a message returned by make_report when the actor is initialized.

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_forver, but dispatches to the stepper.

pub fn start(
  io_driver: IoDriver(io, i, o),
  timeout: Int,
  state: s,
  handle_input: fn(drift.Context(i, o), s, i) -> drift.Step(
    s,
    i,
    o,
    e,
  ),
) -> Result(process.Subject(i), actor.StartError)

Starts a simple actor linked to the current process. No supervision. On success, messages sent to the returned Subject will be handled by the given input handling function, and the actor will take care of all state transitions.

pub fn using_io(
  init: fn() -> state,
  get_selector: fn(state) -> process.Selector(input),
  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.

Search Document