Skip to main content

fromAsyncIterable

Types

function fromAsyncIterable<GValue>(
asyncIterable: AsyncIterable<GValue>,
): IObservable<IFromAsyncIterableObservableNotifications<GValue>>;

Definition

Creates an Observable from an AsyncIterable. It emits values in the form of Notifications.

See fromAsyncIterator for more details.

Diagram

OUTfromAsyncIterable(iterable)OUTfromAsyncIterable(iterable)calls 'iterable.next' and awaitsalt[state isn't done][state is done]alt[fulfilled with <state>][rejected with <error>]loop[until: complete, error, orunsubscribe]next: state.valuecompleteerror: error

Example

Simple AsyncIterable which emits values from 0 to 9

const subscribe = fromAsyncIterable(
(async function * () {
for (let i = 0; i < 10; i++) {
yield i;
}
})()
);

subscribe((notification) => {
console.log(notification.name, ':', notification.value);
});

Output:

next: 0
next: 1
...
next: 9
complete