Class: CURSOR

CURSOR

A simple cursor-like implementation that combines generator and stream functionality. Cursor exposes all the normal stream methods such as pipe, unpipe, on, once etc as well as an initialize method that returns a generator and allows for documents to be iteratively resolved. Using both the generator based cursor interface and stream interface concurrently is not recommended as both utilize the TransformStream on data, on error and on finish events and as such will likely cause unpredictable behavior

Constructor

new CURSOR(optionsopt)

Constructor for Cursor class

Parameters:
Name Type Attributes Default Description
options Object <optional>
{}

Configurable options for cursor (see TransformStream documentation for more details)

Properties
Name Type Description
objectMode Boolean

Unlike a normal transform stream the cursor class is meant for documents and as such objectMode will always be true unless explicitly declared as false at initialization

Source:

Extends

  • TranformStream

Methods

_next() → {Object}

Internally used _next method (this should never be accessed directly). Resumes the transform stream and resolves the next document before pausing the stream

Source:
Returns:

Returns a Promise which resolves with the next document written to the stream

Type
Object

initialize(onSuccessopt, onErroropt) → {function}

Initializes the cursor interface. Once initialized the generator will yield a single document with each next call. The behavior can be modified by passing an onSuccess function as the first argument with each next call. Once cursor is initialized the streams finish, data and error events will have registered listeners

Parameters:
Name Type Attributes Default Description
onSuccess function <optional>
defaultSuccess

A default function to be called on each successful .next call. This function can be temporarily overridden by passing a function in the .next call

onError function <optional>
defaultError

A default function to be called when a .next call results in an rejection

Source:
Returns:

Returns a generator that iteratively resolves the documents written to the stream

Type
function