Coder Social home page Coder Social logo

asynciterable's Introduction

asynciterable

Travis Build Status NPM downloads

Async iterable class

AsyncIterable is a class that implement the async iterable JavaScript pattern, using a semantic similar to the promise one.

Usage

Create an async iterable that emit three numbers:

import AsyncIterable from 'asynciterable';

const numbers = new AsyncIterable((write, end, error) => {
  write(1);
  write(2);
  write(3);
  end();
});

for await (const n of numbers) {
  console.log(n)
}

// Output: 1\n2\n3\n

API

AsyncIterable

A class that implement the async iterable JavaScript pattern, using a semantic similar to the promise one.

Parameters

  • executor Function A function that is passed with the arguments write, end, error. The executor function is executed immediately by the AsyncIterable implementation, passing write, end and error functions (the executor is called before the AsyncIterable constructor even returns the created object). The write function, when called, make the async iterable emit a new item. The end function, when called, make the async iterable end. The error function make it throw an error. The executor normally initiates some asynchronous work, and then, once a new item is available, it emit it by calling the write function, or else call the error function if an error occurred. If an error is thrown in the executor function, any subsequent call to iterator next is rejected with the same error. The return value of the executor is ignored, unless if it is a promise. In this case, when it fullfills to a rejection, error function is automatically called.

Install

With npm installed, run

npm install --save asynciterable

See Also

License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.