Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

asynciterators

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

asynciterators

A collection of async iteration methods

  • 1.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

asynciterators

A collection of async iteration methods for Javascript/Node.

Installation

$ npm install asynciterators --save

Examples

There's examples in the documentation in the source code for each of the methods, but here they are for your viewing pleasure:

asyncForEach

Takes an array and iterates through the collection asynchronously by calling the provided callback function for every time next() is called. When finished, the done() callback will be called if provided. If the loop should be broken, it's possible to call done() whenever you like. By default, it ensures that each iteration is called at the end of each call stack and thus won't block rendering. You can disable this behavior with the fourth argument:

asyncForEach(Array<T>, function(item: T, index: number, next: function, ?done: function), ?onDone: function, ?blockRenderingThread: boolean)

Example:

const arr = ["Foo", "Bar", "Baz"];
 
asyncForEach(arr, (item, index, next, done) => {
      awaitCoolAsyncStringOperation(item)
          .then(next);
}, () => {
      //Called when all collection items has been iterated over or done() is explicitly called.
});

asyncUntil

Will execute the given callback asynchronously at the end of each call stack for every time next() is called. In order to stop execution, done() should be explicitly called.

asyncUntil(function(next: function, done: function), ?onDone: function);

Example:

asyncUntil((next, done) => {
    if (somethingIsReady) done();
    else awaitSomeStuff()
            .then(next)
}, () => {
    //Called when done() is called.
});

parallel

Will take an array of functions and execute them in parallel and call done() if given when all function has finished executing (asynchronously).

parallel([...function(onDone: function)])

Example:

parallel([
             (done) => {
                 awaitReady()
                   .then(done)
                   .catch(done)
             },
             (done) => {
                 awaitSomeThingElse()
                   .then(done)
                   .catch(done)
             }
         ], (error, data) => {
             if (error) throw new Error("Error, wow!!");
             console.log("Data ready!!!");
         });

Usage

Simply do npm install asynciterators --save;

And then all that's left is to import what you want:

import {asyncForEach} from "asynciterators";

or

const asyncForEach = require("asynciterators).asyncForEach;

License

Copyright (c) 2016 Dlmma IVS. Released under the MIT license.

Keywords

FAQs

Package last updated on 02 Jul 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc