Options
All
  • Public
  • Public/Protected
  • All
Menu

Class StreamImpl

Implementation of the Stream interface.

inheritdoc

Hierarchy

  • StreamImpl

Implements

Index

Constructors

constructor

  • Create a new Stream object

    Parameters

    • helper: StreamConstructionHelper
    • Optional events: string[]

      a list of allowed event names. If events is not specified then any events are allowed in the on and off methods. If events are specified, then any event listener will be checked agains the list of allowed events. The events close, error, and complete are always allowed because they are used by Stream and Result internally.

    Returns StreamImpl

Properties

Private Optional allowedEvents

allowedEvents: string[]

The list of allowed event names

Private closeCallback

closeCallback: close

A callback to call when the stream is closed

Private errorCallback

errorCallback: error

A callback to call in the case of an error

Private listeners

listeners: Listeners

The listeners attached to this stream

Methods

Private attach

  • Set one or more properties on an object;

    Parameters

    • key: string | CallbackMap

      The key, or an object map of properties

    • Optional value: StreamCallback

      If the key is a string, this is the value to be associated with it

    Returns void

    The object, with attached properties

close

  • inheritdoc

    Will cause closeCallback to be called.

    Parameters

    • Optional reason: any

      the reason for closing the stream. This can be of any type. The type of the close reason should be documented in the class extending StreamImpl.

    Returns Stream

error

  • error(reason: Error): Stream
  • Close the stream. This will emit a 'close' event to any assigned listeners. No further events will be emitted.

    Parameters

    • reason: Error

    Returns Stream

off

  • Remove a listener from a specified event.

    Example:

    // Bind a single listener to the 'foo' event and then deregister it
    var listener = function() {};
    stream.on('foo', listener);
    stream.off('foo', listener);

    Example:

    // Bind a listener to the 'foo' event and deregister all listeners
    var listener = function() {};
    stream.on('foo', listener);
    stream.off('foo');

    Parameters

    Returns Stream

    this stream.

on

  • Register listeners against events.

    A single listener may be bound to an event by passing the event name and listener function.

    Multiple listeners may be bound by passing in a CallbackMap, mapping event names to listener functions.

    Example:

    // Bind a single listener to the 'foo' event
    stream.on('foo', function(arg1, arg2) {
        console.log("Called for 'foo' event", arg1, arg2);
    });

    Example:

    // Bind multiple listeners
    stream.on({
        foo : function() { ... },
        bar : function() { ... },
        baz : function() { ... }
    });

    Parameters

    Returns Stream

    this stream.

Private remove

  • Remove one or more properties from an object

    Parameters

    • key: string | CallbackMap

      The key, or an object map of properties

    • Optional value: StreamCallback

      If the key is a string, this is the value to remove from it

    Returns void

    The object, sans specified properties