spoke/core

Types

A command to be performed, as requested by the user of the client.

pub type Command {
  SubscribeToUpdates(drift.Effect(mqtt.Update))
  UnsubscribeFromUpdates(drift.Effect(mqtt.Update))
  Connect(
    clean_session: Bool,
    will: option.Option(mqtt.PublishData),
  )
  Disconnect(drift.Effect(Nil))
  Subscribe(
    List(mqtt.SubscribeRequest),
    drift.Effect(
      Result(List(mqtt.Subscription), mqtt.OperationError),
    ),
  )
  Unsubscribe(
    List(String),
    drift.Effect(Result(Nil, mqtt.OperationError)),
  )
  PublishMessage(mqtt.PublishData)
  GetPendingPublishes(drift.Effect(Int))
  WaitForPublishesToFinish(
    drift.Effect(Result(Nil, mqtt.OperationError)),
    Int,
  )
}

Constructors

Type alias for the drift context.

pub type Context =
  drift.Context(Input, Output)

The union of all the possible inputs

pub type Input {
  Perform(Command)
  Handle(TransportEvent)
  Timeout(TimedAction)
}

Constructors

All the outputs (side effects)

pub type Output {
  Publish(drift.Action(mqtt.Update))
  OpenTransport
  CloseTransport
  SendData(bytes_tree.BytesTree)
  ReturnPendingPublishes(drift.Action(Int))
  PublishesCompleted(
    drift.Action(Result(Nil, mqtt.OperationError)),
  )
  SubscribeCompleted(
    drift.Action(
      Result(List(mqtt.Subscription), mqtt.OperationError),
    ),
  )
  UnsubscribeCompleted(
    drift.Action(Result(Nil, mqtt.OperationError)),
  )
  CompleteDisconnect(drift.Action(Nil))
  UpdatePersistedSession(session_state.StorageUpdate)
}

Constructors

The state of the MQTT client.

pub opaque type State

Type alias for the drift step.

pub type Step =
  drift.Step(State, Input, Output, String)

An action that happens as a result of timer expiring

pub opaque type TimedAction

An event coming from the transport channel

pub type TransportEvent {
  TransportEstablished
  TransportFailed(String)
  TransportClosed
  ReceivedData(BitArray)
}

Constructors

  • TransportEstablished

    The transport channel is open, and ready to receive data.

  • TransportFailed(String)

    The transport channel failed for some reason.

  • TransportClosed

    The transport channel was closed after requesting it.

  • ReceivedData(BitArray)

    Data was received on the transport channel.

Values

pub fn handle_input(
  context: drift.Context(Input, Output),
  state: State,
  input: Input,
) -> drift.Step(State, Input, Output, String)

Runs one step, handing the given input.

pub fn new_state(options: mqtt.ConnectOptions(a)) -> State

Creates new, clean state.

pub fn restore_state(
  options: mqtt.ConnectOptions(a),
  state: session_state.SessionState,
) -> State

Creates a new state from an existing session.

Search Document