used to subscribe to the underlying event source. The function must return an unsubscribe function to terminate the subscription.
Optionalbuffer: Buffer<T>optional Buffer object to buffer messages on this channel. If not provided, messages will not be buffered on this channel.
Creates channel that will subscribe to an event source using the
subscribemethod. Incoming events from the event source will be queued in the channel until interested takers are registered.To notify the channel that the event source has terminated, you can notify the provided subscriber with an
ENDExample
In the following example we create an event channel that will subscribe to a
setIntervalconst countdown = (secs) => { return eventChannel(emitter => { const iv = setInterval(() => { console.log('countdown', secs) secs -= 1 if (secs > 0) { emitter(secs) } else { emitter(END) clearInterval(iv) console.log('countdown terminated') } }, 1000); return () => { clearInterval(iv) console.log('countdown cancelled') } } ) }