Constructor
new BufferedIterator(optionsopt)
Creates a new BufferedIterator
.
Parameters:
Name | Type | Attributes | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
<optional> |
Settings of the iterator Properties
|
Extends
- module:asynciterator.AsyncIterator
Members
maxBufferSize :number
The maximum number of items to preload in the internal buffer.
A BufferedIterator
tries to fill its buffer as far as possible.
Set to Infinity
to fully drain the source.
Type:
- number
Methods
(protected) _begin(done)
Writes beginning items and opens iterator resources.
Should never be called before BufferedIterator#_init;
typically, _init
is responsible for calling _begin
.
Parameters:
Name | Type | Description |
---|---|---|
done |
function | To be called when initialization is complete |
(protected) _completeClose()
Stops the iterator from generating new items,
switching from CLOSING
state into CLOSED
state.
Fires:
- module:asynciterator.AsyncIterator.event:end
(protected) _fillBuffer()
Fills the internal buffer until this._maxBufferSize
items are present.
This method calls BufferedIterator#_read to fetch items.
Fires:
- module:asynciterator.AsyncIterator.event:readable
_fillBufferAsync()
Schedules _fillBuffer
asynchronously.
(protected) _flush(done)
Writes terminating items and closes iterator resources.
Should never be called before BufferedIterator#close;
typically, close
is responsible for calling _flush
.
Parameters:
Name | Type | Description |
---|---|---|
done |
function | To be called when termination is complete |
(protected) _init(autoStart)
Initializing the iterator by calling BufferedIterator#_begin and changing state from INIT to OPEN.
Parameters:
Name | Type | Description |
---|---|---|
autoStart |
boolean | Whether reading of items should immediately start after OPEN. |
(protected) _push(item)
Adds an item to the internal buffer.
Parameters:
Name | Type | Description |
---|---|---|
item |
object | The item to add |
Fires:
- module:asynciterator.AsyncIterator.event:readable
(protected) _read(count, done)
Tries to generate the given number of items.
Implementers should add count
items through BufferedIterator#_push.
Parameters:
Name | Type | Description |
---|---|---|
count |
integer | The number of items to generate |
done |
function | To be called when reading is complete |
(protected) _toStringDetails()
Generates details for a textual representation of the iterator.
close()
Stops the iterator from generating new items after a possible pending read operation has finished. Already generated, pending, or terminating items can still be emitted. After this, the iterator will end asynchronously.
Fires:
- module:asynciterator.AsyncIterator.event:end
read() → (nullable) {object}
Tries to read the next item from the iterator. If the buffer is empty, this method calls BufferedIterator#_read to fetch items.
Returns:
The next item, or null
if none is available
- Type
- object