libduvet/gateway/feed
Types
One ordered feed for every listener: what its client or manager publishes reaches all of them, in the order it was published.
pub opaque type Feed
What a gateway client tells its listeners.
pub type FeedMessage {
Payload(payload: envelope.GatewayEventPayload)
RawFrame(text: String)
Malformed(cause: String)
StateChanged(state: GatewayConnectionState)
Resumed(shard_id: Int)
Closed(close: envelope.GatewayCloseReason)
ConnectFailed(failure: GatewayConnectFailure)
FeedClosed
}
Constructors
-
Payload(payload: envelope.GatewayEventPayload)A decoded event from the gateway, including READY.
-
RawFrame(text: String)A frame exactly as the gateway sent it: what a client that decodes events itself (a bot, say) reads, without this package’s models in between.
-
Malformed(cause: String)Something the client couldn’t read.
-
StateChanged(state: GatewayConnectionState)The connection’s state changed.
-
Resumed(shard_id: Int)The gateway resumed a shard’s session on a new socket.
-
Closed(close: envelope.GatewayCloseReason)The reason the gateway gave before it closed the socket.
-
ConnectFailed(failure: GatewayConnectFailure)An attempt to open a socket failed.
-
FeedClosedThe client was destroyed; no other message comes.
An attempt to open a socket to the gateway that failed.
pub type GatewayConnectFailure {
GatewayConnectFailure(
shard_id: Int,
failures: Int,
http_status: option.Option(Int),
error: String,
)
}
Constructors
-
GatewayConnectFailure( shard_id: Int, failures: Int, http_status: option.Option(Int), error: String, )Arguments
- shard_id
-
The shard that tried: 0 without sharding.
- failures
-
How many attempts in a row failed, this one included, since a socket last opened: 1 for the first.
- http_status
-
The HTTP status the gateway refused the upgrade with, when it answered.
- error
-
What stopped it.
Where a gateway connection is.
pub type GatewayConnectionState {
Connecting
Connected
Reconnecting
Disconnected
}
Constructors
-
ConnectingOpening the first socket.
-
ConnectedA socket is open and the client identified on it; READY follows, or, when the gateway resumes the session, the events it missed and [FeedMessage.Resumed].
-
ReconnectingThe socket closed, or couldn’t open, and the client is opening another.
-
DisconnectedNo socket, and none opening: before connecting, after a connect that failed with nothing trying again, after the gateway refused the shard, or once destroyed.
Values
pub fn publish(feed: Feed, message: FeedMessage) -> Nil
Publishes to every listener; returns at once.
pub fn subscribe(feed: Feed) -> process.Subject(FeedMessage)
A subject of its own for one listener, registered before this returns, so nothing published after it is missed. The caller owns it.