Module: asynciterator

An asynchronous iterator library for advanced object pipelines

Classes

ArrayIterator
AsyncIterator
BufferedIterator
ClonedIterator
EmptyIterator
IntegerIterator
MappingIterator
MultiTransformIterator
SimpleTransformIterator
SingletonIterator
TransformIterator
UnionIterator
WrappingIterator

Members

(static) CLOSED :integer

ID of the CLOSED state. An iterator is closed if it no longer actively generates new items. Items might still be available.

Type:
  • integer

(static) CLOSING :integer

ID of the CLOSING state. An iterator is closing if item generation is pending but will not be scheduled again.

Type:
  • integer

(static) DESTINATION

Key indicating the current consumer of a source.

(static) DESTROYED :integer

ID of the DESTROYED state. An iterator has been destroyed after calling module:asynciterator.AsyncIterator#destroy. The 'end' event has not been called, as pending elements were voided.

Type:
  • integer

(static) ENDED :integer

ID of the ENDED state. An iterator has ended if no further items will become available. The 'end' event is guaranteed to have been called when in this state.

Type:
  • integer

(static) INIT :integer

ID of the INIT state. An iterator is initializing if it is preparing main item generation. It can already produce items.

Type:
  • integer

(static) OPEN :integer

ID of the OPEN state. An iterator is open if it can generate new items.

Type:
  • integer

Methods

(inner) empty()

Creates an empty iterator.

(inner) fromArray(items)

Creates an iterator for the given array.

Parameters:
Name Type Description
items Array

the items

(inner) fromIterable(source)

Creates an iterator for the given Iterable.

Parameters:
Name Type Description
source Iterable

the iterable

(inner) fromIterator(source)

Creates an iterator for the given Iterator.

Parameters:
Name Type Description
source Iterable

the iterator

(inner) getTaskScheduler()

Returns the asynchronous task scheduler.

(inner) identity()

Function that maps an element to itself.

(inner) range(items)

Creates an iterator of integers for the given numeric range.

Parameters:
Name Type Description
items Array

the items

(inner) scheduleTask()

Schedules the given task for asynchronous execution.

(inner) setTaskScheduler()

Sets the asynchronous task scheduler.

(inner) single(item)

Creates an iterator with a single item.

Parameters:
Name Type Description
item object

the item

(inner) union(items)

Creates an iterator containing all items from the given iterators.

Parameters:
Name Type Description
items Array

the items

(inner) wrap(sourceopt, optionsopt) → {module:asynciterator.AsyncIterator}

Creates an iterator that wraps around a given iterator or readable stream. Use this to convert an iterator-like object into a full-featured AsyncIterator. After this operation, only read the returned iterator instead of the given one.

Parameters:
Name Type Attributes Description
source <optional>

The source this iterator generates items from

options object <optional>

Settings of the iterator

Returns:

A new iterator with the items from the given iterator

Type
module:asynciterator.AsyncIterator

Events

data

The iterator emits a data event with a new item as soon as it becomes available. When one or more listeners are attached to the data event, the iterator switches to flow mode, generating and emitting new items as fast as possible. This drains the source and might create backpressure on the consumers, so only subscribe to this event if this behavior is intended. In flow mode, don't use module:asynciterator.AsyncIterator#read. To switch back to on-demand mode, remove all listeners from the data event. You can then obtain items through read again.

Parameters:
Name Type Description
item object

The new item

end

The end event is emitted after the last item of the iterator has been read.

readable

The iterator emits a readable event when it might have new items available after having had no items available right before this event. If the iterator is not in flow mode, items can be retrieved by calling module:asynciterator.AsyncIterator#read.