libduvet/gateway/client
Types
How a gateway client is set up.
pub type Config {
Config(
api: client.RestClient,
router: api_router.ApiRouter,
shard_id: Int,
shard_count: Int,
connect_timeout: Int,
resume: Bool,
platform: option.Option(client_platform.ClientPlatform),
log: fn(String) -> Nil,
feed: feed.Feed,
)
}
Constructors
-
Config( api: client.RestClient, router: api_router.ApiRouter, shard_id: Int, shard_count: Int, connect_timeout: Int, resume: Bool, platform: option.Option(client_platform.ClientPlatform), log: fn(String) -> Nil, feed: feed.Feed, )
Why a connect call ended without a socket.
pub type ConnectFailure {
Destroyed
Failed(feed.GatewayConnectFailure)
}
Constructors
-
DestroyedAnother attempt replaced this one, or the client was destroyed.
-
Failed(feed.GatewayConnectFailure)The attempt failed; see the failure.
A single WebSocket connection to the gateway, kept by a process of its own. It owns its heartbeat loop, reconnect logic and sequence tracking, and tells its listeners through the feed it was given.
pub opaque type GatewayClient
Values
pub fn config(api: client.RestClient, feed: feed.Feed) -> Config
pub fn connect(
gateway: GatewayClient,
) -> Result(Nil, ConnectFailure)
Opens a socket and identifies on it, after closing the one open before.
pub fn connection(gateway: GatewayClient) -> option.Option(Int)
The number of the socket open now (they’re counted from 1 as they open), or None while none is.
pub fn connection_state(
gateway: GatewayClient,
) -> feed.GatewayConnectionState
pub const default_connect_timeout: Int
How long opening a socket to the gateway may take before the attempt is dropped: 15 seconds.
pub fn destroy(gateway: GatewayClient) -> Nil
pub fn reconnect(gateway: GatewayClient) -> Bool
Closes the socket, if one is open, and opens a new one: after a delay that grows with each failed attempt, it tries until a socket opens or the client is destroyed. Answers whether a socket opened.
pub fn reconnect_delay(failed: Int, jitter_ms: Int) -> Int
How long the client waits before it opens another socket, after [failed] attempts in a row failed to open one (none when an open socket dropped): a second, doubling with each failure, up to 30, plus up to a second at random, so that clients don’t all come back at once.
pub fn retry_now(gateway: GatewayClient) -> Bool
pub fn send_message(
gateway: GatewayClient,
type_: String,
data: json.Json,
) -> Bool
Sends an event message, and answers whether it went out on an open socket.
pub fn silence_before_ready(
gateway: GatewayClient,
) -> duration.Duration
How long the gateway had been silent before the last READY.
pub fn start(config: Config) -> GatewayClient
pub fn wait_for_connection(gateway: GatewayClient) -> Bool
pub fn want_fresh_session(gateway: GatewayClient) -> Nil
pub fn with_platform(
config: Config,
platform: client_platform.ClientPlatform,
) -> Config
pub fn with_router(
config: Config,
router: api_router.ApiRouter,
) -> Config