lightspeed/channel

Channel runtime model with topic routing, pubsub, and presence.

Types

Channel

opaque

Channel state.

pub opaque type Channel

Inbound channel events.

pub type Event {
  Join(
    client_id: String,
    topic: String,
    user_id: String,
    now_ms: Int,
  )
  Rejoin(
    client_id: String,
    topic: String,
    user_id: String,
    now_ms: Int,
  )
  Leave(client_id: String, topic: String)
  Broadcast(client_id: String, topic: String, payload: String)
  Push(
    client_id: String,
    topic: String,
    event: String,
    payload: String,
  )
  Crash(reason: String)
  Restart
}

Constructors

  • Join(
      client_id: String,
      topic: String,
      user_id: String,
      now_ms: Int,
    )
  • Rejoin(
      client_id: String,
      topic: String,
      user_id: String,
      now_ms: Int,
    )
  • Leave(client_id: String, topic: String)
  • Broadcast(client_id: String, topic: String, payload: String)
  • Push(
      client_id: String,
      topic: String,
      event: String,
      payload: String,
    )
  • Crash(reason: String)
  • Restart

Outbound channel messages.

pub type Outbound {
  Reply(
    client_id: String,
    topic: String,
    status: String,
    payload: String,
  )
  PushMessage(
    client_id: String,
    topic: String,
    event: String,
    payload: String,
  )
  BroadcastMessage(
    topic: String,
    payload: String,
    recipients: List(String),
  )
  PresenceDiff(topic: String, diff: presence.Diff)
  System(label: String)
}

Constructors

  • Reply(
      client_id: String,
      topic: String,
      status: String,
      payload: String,
    )
  • PushMessage(
      client_id: String,
      topic: String,
      event: String,
      payload: String,
    )
  • BroadcastMessage(
      topic: String,
      payload: String,
      recipients: List(String),
    )
  • PresenceDiff(topic: String, diff: presence.Diff)
  • System(label: String)

Values

pub fn adapter_label(channel: Channel) -> String

PubSub adapter label.

pub fn crashed(channel: Channel) -> Bool

True when channel is crashed.

pub fn event_label(event: Event) -> String

Stable event label.

pub fn flush_outbox(
  channel: Channel,
) -> #(Channel, List(Outbound))

Flush outbox in emit order.

pub fn handle(channel: Channel, event: Event) -> Channel

Handle one channel event.

pub fn membership_count(channel: Channel) -> Int

Membership count.

pub fn new_cluster_ready(
  node_id: String,
  cluster: String,
) -> Channel

Start a cluster-ready channel.

pub fn new_single_node() -> Channel

Start a single-node channel.

pub fn outbound_label(outbound: Outbound) -> String

Stable outbound label.

pub fn presences(
  channel: Channel,
  topic: String,
) -> List(presence.Entry)

Presence entries for one topic.

pub fn subscribers(
  channel: Channel,
  topic: String,
) -> List(String)

Subscribers for one topic.

Search Document