@alwaysblank/denden
    Preparing search index...

    Function only

    • Run callback only if test evaluates to true.

      Type Parameters

      • Payload extends unknown

      Parameters

      • hub: Hub

        The hub this listener should attach to.

      • channel: ChannelRoute

        The channel to subscribe to.

      • callback: Callback<Payload>

        Called with the payload, message, and unsub function when a message is published.

      • test: (payload: Payload, message: Message<Payload>) => boolean

        Function that determines if the callback should be invoked.

      • OptionalonlyFuture: boolean = false

        If true, callback will fire only for messages dispatched in the future. If false, messages in the backlog will also be considered.

      Returns (reason?: string) => void

      const hub = new Hub();

      only(hub, 'sandwiches', (p) => console.log(`only: ${p}`), (p) => p.includes('reuben'));

      hub.pub('sandwiches', 'reuben sandwich');
      // "only: reuben sandwich"
      hub.pub('sandwiches', 'chicken sandwich');
      // Nothing printed.