Skip to content

Latest commit

 

History

History
91 lines (50 loc) · 3.03 KB

channel.md

File metadata and controls

91 lines (50 loc) · 3.03 KB

Class: Channel

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.

Channel(options?)

Initializes a new Channel.

const { Channel } = require('downstream');

const channel = new Channel({ capacity: 100 });

Event: error

Emitted when an error occurs.

Event: empty

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.

Event: notEmpty

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.

channel.started

  • Type: boolean

Whether this Channel is running after being started with channel.start().

channel.start()

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

channel.stop()

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

channel.enqueue(item)

Enqueues an Item from some external source onto the internal queue.

channel.dequeue()

  • 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.

channel.isEmpty()

  • Returns: boolean

Returns whether the internal queue is empty.

Interface: ChannelOptions

channelOptions.capacity?

  • Type: number
  • Default: 200

The capacity of the internal Channel queue.