- extends
EventEmitter
A Channel represents a stream of Items from some external data source, like a web API.
Internally, Channels work by maintaining a circular queue of some fixed capacity that temporarily stores as many Items as possible until they can be dequeued and fed into the Downstream instance to which this Channel is registered.
options?
: ChannelOptions
Initializes a new Channel.
const { Channel } = require('downstream');
const channel = new Channel({ capacity: 100 });
err
: an Error object
Emitted when an error occurs.
Emitted when the internal queue is empty after storing some number of Items.
This event is used by a Downstream instance to know when Items are available to dequeue.
Emitted when the internal queue has some number of Items after being empty.
This event is used by a Downstream instance to know when Items are available to dequeue.
- Type:
boolean
Whether this Channel is running after being started with channel.start()
.
- Returns: Promise<void>
Starts this Channel so that it will stream Items from some external source. Depending on the type of Channel, "starting" could mean:
- starting an HTTP stream
- adding listeners to events
- scheduling the first
setTimeout
to poll a web API
- Returns: Promise<void>
Stops this Channel so that it will stop streaming Items from some external source. Depending on the type of Channel, "stopping" could mean:
- stopping an HTTP stream
- removing listeners from events
- clearing the next
setTimeout
to stop polling a web API
item
: Item
Enqueues an Item from some external source onto the internal queue.
- Returns: Item |
null
Dequeues an Item from the internal queue, if available.
This function is used by a Downstream instance to feed Items from this Channel to a set of hooks.
- Returns:
boolean
Returns whether the internal queue is empty.
- Type:
number
- Default:
200
The capacity of the internal Channel queue.