pamoja for TypeScript - v0.2.0
    Preparing search index...

    Class Transport

    One transport: a link to drive with connect, subscribe, send, and recv, or to compose into a ladder or a wrapper.

    Build one with the static factories, then drive it or hand it to whatever should own it. A transport handed on is spent: calling anything on it afterwards throws.

    Index
    • get isAvailable(): boolean

      Whether this transport is still holdable, or has been handed on.

      Returns boolean

    • Establishes the link. Rejects when it cannot be established, or when the transport was handed on.

      Returns Promise<void>

    • Waits for the next message on a subscribed topic, or null once the link has ended. Rejects when the link fails, or when the transport was handed on.

      Parameters

      • OptionaltimeoutMs: number | null

        how long to wait before rejecting; a message that arrives later waits for the next receive. Without it the receive waits as long as it takes.

      Returns Promise<core.TransportMessage | null>

    • Publishes a payload to a topic: bytes, or text such as a reading written out. Rejects when the link refuses it, or when the transport was handed on.

      Parameters

      • topic: string
      • payload: string | Buffer<ArrayBufferLike>

      Returns Promise<void>

    • Subscribes to a topic, with the + and # wildcards. Rejects when the link refuses it, or when the transport was handed on.

      Parameters

      • topic: string

      Returns Promise<void>

    • Wraps a transport in a link that loses packets and goes down.

      The wrapped transport is consumed. Every fault is off unless the options name it, so a link that only drops packets says only that.

      Parameters

      • inner: core.Transport

        the transport to degrade.

      • Optionalfaults: Faults | null

        dropEvery loses one send in every this many; up and down alternate that many sends of reachable and unreachable.

      Returns core.Transport

    • Wraps a transport so its next failures sends fail.

      This is how a caller checks that a ladder falls through to its next rung, or that a buffer fills, without unplugging anything. The wrapped transport is consumed.

      Parameters

      Returns core.Transport

    • Wraps a link written in JavaScript as a transport.

      handlers needs connect(), send(topic, payload), and subscribe(topic), each returning a promise or nothing. A recv() that resolves to a message, { topic, payload } with the payload as a buffer or text, or to null once the link has ended, makes it a link that delivers: it is called again as soon as it settles, from the moment the transport connects. A recv that throws ends the link until the next connect, and the next receive rejects with what it threw. Without recv the transport only sends, and a ladder never listens on it. The methods are called on handlers, so a class instance works as it is.

      Parameters

      • handlers: {
            connect(): void | Promise<void>;
            recv?(): | core.DeliveredMessage
            | Promise<core.DeliveredMessage | null | undefined>
            | null
            | undefined;
            send(topic: string, payload: Buffer): void | Promise<void>;
            subscribe(topic: string): void | Promise<void>;
        }

      Returns core.Transport