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

    Class EventBus

    One endpoint on an event bus.

    An endpoint both publishes and receives, and it receives what it publishes itself. Each subscriber needs its own, taken with subscribe, because an endpoint only sees events published after it existed. Only next and nextText wait: publishing and subscribing return at once, even while a next on the same endpoint is waiting.

    Index
    • Creates an event bus.

      Parameters

      • Optionalcapacity: number | null

        how many events a slow subscriber may fall behind before it starts missing them, rounded up to the next power of two and at most 1048576; 64 when not given.

      Returns bus.EventBus

    • get missed(): number

      How many events this endpoint lost by falling behind, as of its last completed wait.

      Returns number

    • Waits for the next event on this endpoint.

      Parameters

      • OptionaltimeoutMs: number | null

        how long to wait before throwing; the next event is then left for the next call. Without it, the wait lasts until an event arrives.

      Returns Promise<Buffer<ArrayBufferLike>>

    • Waits for the next event as text.

      Throws if the event is not UTF-8 text.

      Parameters

      • OptionaltimeoutMs: number | null

        how long to wait before throwing; the next event is then left for the next call. Without it, the wait lasts until an event arrives.

      Returns Promise<string>

    • Publishes an event to every subscriber, this endpoint included: bytes, or text such as an event name.

      It never waits: a subscriber that has fallen behind loses its oldest event rather than holding up the publisher.

      Parameters

      • event: string | Buffer<ArrayBufferLike>

      Returns void

    • Takes another endpoint on the same bus.

      The new endpoint sees events published from now on, not those already sent, so subscribe before publishing anything it needs to see.

      Returns bus.EventBus