Synclets logoSynclets

TransportImplementations

The TransportImplementations type lists the async connect, disconnect, and sendPacket callbacks a Transport requires to operate.

{
  connect?: (receivePacket: (string: string) => Promise<void>) => Promise<void>;
  disconnect?: () => Promise<void>;
  sendPacket: (string: string) => Promise<void>;
}
TypeDescription
connect?(receivePacket: (string: string) => Promise<void>) => Promise<void>

The connect callback is invoked when the Synclet starts. It receives a receivePacket function that must be called whenever a packet arrives from remote peers. The callback should establish the underlying communication channel (e.g., opening a WebSocket, subscribing to a message bus) and wire up incoming message handlers to call receivePacket.

disconnect?() => Promise<void>

The disconnect callback is invoked when the Synclet is destroyed. It should close the underlying communication channel (e.g., closing a WebSocket, unsubscribing from a message bus) and clean up any allocated resources. The transport will not be used after this callback returns.

sendPacket(string: string) => Promise<void>

The sendPacket callback must transmit the provided packet string to remote peers through the underlying communication channel. Packets may be fragments of larger messages depending on the configured fragmentSize. The callback should handle transmission failures gracefully and may queue packets if the channel is not immediately ready.

Since

v0.0.0