Skip to main content
Module

x/ldkit/library/asynciterator.ts>AsyncIterator

LDkit - Linked Data query toolkit for TypeScript developers
Go to Latest
class AsyncIterator
extends EventEmitter
Re-export
import { AsyncIterator } from "https://deno.land/x/ldkit@v0.6.4/library/asynciterator.ts";

An asynchronous iterator provides pull-based access to a stream of objects.

Constructors

new
AsyncIterator(initialState?: number)

Creates a new AsyncIterator.

Properties

private
_readable
protected
optional
_properties: { [name: string]: any; }
protected
optional
_propertyCallbacks: { [name: string]: [(value: any) => void]; }
protected
_state: number
readonly
closed: boolean

Gets whether the iterator has stopped generating new items.

readonly
destroyed: boolean

Gets whether the iterator has been destroyed.

readonly
done: boolean

Gets whether the iterator will not emit anymore items, either due to being closed or due to being destroyed.

readonly
ended: boolean

Gets whether the iterator has finished emitting items.

readable: boolean

Gets or sets whether this iterator might have items available for read. A value of false means there are definitely no items available; a value of true means items might be available.

Methods

protected
_changeState(newState: number, eventAsync?: boolean): boolean

Changes the iterator to the given state if possible and necessary, possibly emitting events to signal that change.

protected
_destroy(cause: Error | undefined, callback: (error?: Error) => void): void

Called by module:asynciterator.AsyncIterator#destroy. Implementers can override this, but this should not be called directly.

protected
_end(destroy?: boolean): void

Ends the iterator and cleans up. Should never be called before module:asynciterator.AsyncIterator#close; typically, close is responsible for calling _end.

protected
_endAsync(): void

Asynchronously calls _end.

protected
_toStringDetails(): string

Generates details for a textual representation of the iterator.

Appends the items after those of the current iterator. After this operation, only read the returned iterator instead of the current one.

clone(): ClonedIterator<T>

Creates a copy of the current iterator, containing all items emitted from this point onward. Further copies can be created; they will all start from this same point. After this operation, only read the returned copies instead of the original iterator.

close(): void

Stops the iterator from generating new items. Already generated items or terminating items can still be emitted. After this, the iterator will end asynchronously.

copyProperties(source: AsyncIterator<any>, propertyNames: string[]): void

Copies the given properties from the source iterator.

destroy(cause?: Error): void

Destroy the iterator and stop it from generating new items. This will not do anything if the iterator was already ended or destroyed. All internal resources will be released an no new items will be emitted, even not already generated items. Implementors should not override this method, but instead implement module:asynciterator.AsyncIterator#_destroy.

filter<K extends T>(filter: (item: T) => item is K, self?: any): AsyncIterator<K>

Return items from this iterator that match the filter. After this operation, only read the returned iterator instead of the current one.

filter(filter: (item: T) => boolean, self?: any): AsyncIterator<T>
forEach(callback: (item: T) => void, self?: object): void

Invokes the callback for each remaining item in the iterator. Switches the iterator to flow mode.

getProperties(): { [name: string]: any; }

Retrieves all properties of the iterator.

getProperty<P>(propertyName: string, callback?: (value: P) => void): P | undefined

Retrieves the property with the given name from the iterator. If no callback is passed, it returns the value of the property or undefined if the property is not set. If a callback is passed, it returns undefined and calls the callback with the property the moment it is set.

map<D>(map: MapFunction<T, D>, self?: any): AsyncIterator<D>

Maps items from this iterator using the given function. After this operation, only read the returned iterator instead of the current one.

Prepends the items after those of the current iterator. After this operation, only read the returned iterator instead of the current one.

range(start: number, end: number): AsyncIterator<T>

Limits the current iterator to the given range. The current iterator may not be read anymore until the returned iterator ends.

read(): T | null

Tries to read the next item from the iterator. This is the main method for reading the iterator in on-demand mode, where new items are only created when needed by consumers. If no items are currently available, this methods returns null. The module:asynciterator.event:readable event will then signal when new items might be ready. To read all items from the iterator, switch to flow mode by subscribing to the module:asynciterator.event:data event. When in flow mode, do not use the read method.

setProperties(properties: { [name: string]: any; }): void

Sets all of the given properties.

setProperty<P>(propertyName: string, value: P): void

Sets the property with the given name to the value.

skip(offset: number): AsyncIterator<T>

Skips the given number of items from the current iterator. The current iterator may not be read anymore until the returned iterator ends.

surround(prepend: AsyncIteratorOrArray<T>, append: AsyncIteratorOrArray<T>): AsyncIterator<T>

Surrounds items of the current iterator with the given items. After this operation, only read the returned iterator instead of the current one.

take(limit: number): AsyncIterator<T>

Limits the current iterator to the given number of items. The current iterator may not be read anymore until the returned iterator ends.

toArray(options?: { limit?: number; }): Promise<T[]>

Consume all remaining items of the iterator into an array that will be returned asynchronously.

toString(): string
transform<D>(options: TransformOptions<T, D>): AsyncIterator<D>

Transforms items from this iterator. After this operation, only read the returned iterator instead of the current one.

uniq(by?: (item: T) => any): AsyncIterator<T>

Returns a new iterator containing all of the unique items in the original iterator.