Async concurrent iterator (async forEach)

Overview

each-async

Async concurrent iterator (async forEach)

Like async.each(), but tiny.

I often use async.each() for doing async operations when iterating, but I almost never use the other gadzillion methods in async.

Async iteration is one of the most used async control flow patterns.

I would strongly recommend using promises instead. You could then use the built-in Promise.all(), or p-map if you need concurrency control.

Install

$ npm install --save each-async

Usage

const eachAsync = require('each-async');

eachAsync(['foo','bar','baz'], (item, index, done) => {
	console.log(item, index);
	done();
}, error => {
	console.log('finished');
});
//=> 'foo 0'
//=> 'bar 1'
//=> 'baz 2'
//=> 'finished'

API

eachAsync(input, callback, [finishedCallback])

input

Type: Array

Array you want to iterate.

callback(item, index, done)

Type: Function

Called for each item in the array with the following arguments:

  • item: the current item in the array
  • index: the current index
  • done([error]): call this when you're done with an optional error. Supplying anything other than undefined/null will stop the iteration.

Note that order is not guaranteed since each item is handled concurrently.

finishedCallback(error)

Type: Function

Called when the iteration is finished or on the first error. First argument is the error passed from done() in the callback.

License

MIT © Sindre Sorhus

You might also like...

Async utilities for node and the browser

Async utilities for node and the browser

Async is a utility module which provides straight-forward, powerful functions for working with asynchronous JavaScript. Although originally designed f

Dec 31, 2022

An async control-flow library that makes stepping through logic easy.

Step A simple control-flow library for node.JS that makes parallel execution, serial execution, and error handling painless. How to install Simply cop

Dec 22, 2022

A solid, fast Promises/A+ and when() implementation, plus other async goodies.

when.js When.js is a rock solid, battle-tested Promises/A+ and when() implementation, including a complete ES6 Promise shim. It's a powerful combinati

Dec 18, 2022

utility library for async iterable iterators

utility library for async iterable iterators

⚠️ This library is no longer maintained, and should not be used in production applications. Mesh is a utility library for async iterable iterators. Mo

Jul 29, 2022

Expressive middleware for node.js using ES2017 async functions

Expressive middleware for node.js using ES2017 async functions

Expressive HTTP middleware framework for node.js to make web applications and APIs more enjoyable to write. Koa's middleware stack flows in a stack-li

Jan 4, 2023

CSP channels for Javascript (like Clojurescript's core.async, or Go) THIS IS AN UPSTREAM FORK

js-csp Communicating sequential processes for Javascript (like Clojurescript core.async, or Go). Examples var csp = require("js-csp"); Pingpong (porte

Sep 22, 2022

An extension to Async adding better handling of mixed Series / Parallel tasks via object chaining

async-chainable Flow control for NodeJS applications. This builds on the foundations of the Async library while adding better handling of mixed Series

Jul 15, 2019

⚖️ Limit an async function's concurrency with ease!

limit-concur Limit an async function's concurrency with ease! Install $ npm i limit-concur Usage import got from 'got' import limitConcur from 'limit-

Apr 8, 2022

Async cache with dedupe support

async-cache-dedupe async-cache-dedupe is a cache for asynchronous fetching of resources with full deduplication, i.e. the same resource is only asked

Dec 8, 2022

A platformer game using Phaser3 library and Vanilla JS. This project features the knowledge of Webpack, ES6, JS Modules, Async code, DOM, JSON and Jest tests.

A platformer game using Phaser3 library and Vanilla JS. This project features the knowledge of Webpack, ES6, JS Modules, Async code, DOM, JSON and Jest tests.

RUNNING BUNNY A platformer game using Phaser3 library and Vanilla JS. This project features the knowledge of Webpack, ES6, JS Modules, Async code, DOM

Mar 29, 2022

This simple project, show how work with async Fetch, function component and class component

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

Feb 17, 2022

Run async code one after another by scheduling promises.

promise-scheduler Run async code in a synchronous order by scheduling promises, with the possibility to cancel pending or active tasks. Optimized for

Dec 17, 2021

This branch is created to make receive and send data to api using async and await methods

This branch is created to make receive and send data to api using async and await methods

Microverse-Leader-Board Project from module 2 week 4 This branch is created to make receive and send data to api using async and await methods Screens

Apr 22, 2022

A markdown-it plugin and Nunjucks async filter to make working with Cloudinary in Eleventy easier.

Cloudinary Eleventy Helpers This is a collection of Eleventy Cloudinary helpers. It currently includes: A markdown-it plugin that converts local image

Feb 2, 2022

Async node.js implementation of the UDP Minecraft Server Query Protocol and TCP Minecraft Server List Ping Protocol

🔎 Mc Server Status Async node.js implementation of the UDP Minecraft Server Query Protocol and TCP Minecraft Server List Ping Protocol. Also availabl

Nov 10, 2022

Debounce promise-returning & async functions.

perfect-debounce An improved debounce function with Promise support. Well tested debounce implementation Native Promise support Avoid duplicate calls

Jan 2, 2023

Converts an iterable, iterable of Promises, or async iterable into a Promise of an Array.

iterate-all A utility function that converts any of these: IterableT IterablePromiseT AsyncIterableT AsyncIterablePromiseT Into this: Prom

Jun 7, 2022

Mirrors the functionality of Apollo client's useQuery hook, but with a "query" being any async function rather than GQL statement.

useAsyncQuery Mirrors the functionality of Apollo client's useQuery hook, but with a "query" being any async function rather than GQL statement. Usage

Nov 16, 2022

Projeto de Botnet com Python, Websockets, Async e Javascript

Projeto de Botnet com Python, Websockets, Async e Javascript

A3 - Botnets Este é um repositório onde documentarei todo o processo de pesquisa e desenvolvimento de uma botnet do zero com python, websockets e asyn

Sep 23, 2022
Comments
  • Concurrency option

    Concurrency option

    Just the same, but in series.

    What do you think to add an extra param to do this action? like:

    js
    const concurrency = 1;
    
    eachAsync(['foo','bar','baz'], concurrency, (item, index, done) => {
        console.log(item, index);
        done();
    }, error => {
        console.log('finished');
    }
    
    enhancement help wanted 
    opened by Kikobeats 4
  • EJSONPARSE - @0.1.3

    EJSONPARSE - @0.1.3

    When i'm running the yeoman generator for angular i get the following error:

    screen shot 2014-09-03 at 12 45 28 pm

    I've checked the package.json in the 0.1.3-tag, but everything seems to be ok.

    opened by timoweiss 3
  • is necessary to ensure async iterator?

    is necessary to ensure async iterator?

    I want to know, if using this package, need to be sure that the iterator function that you put in the method need to be ensure async.

    I really don't know if this is a problem about how internally async works or if is a JS/Node behaviour.

    can you clarify this?

    standalone async.ensureAsync => https://github.com/Kikobeats/ensure-async#ensure-async

    opened by Kikobeats 2
  • fix test

    fix test

    Is this what you really wanted to do?

    Also, I have a question: is this really a parallel-each? I mean, the next callback is called in order for every array element and since javascript is single threaded, every call will be executed sequentially and in order. The closest thing to a parallel execution that one could do (it's really just an async execution, anyway) is passing a callback that wraps all its content in a setTimeout so that the callbacks will be executed asynchronously (like you've done in the first test) but this is up to the user of the each-async, it's not done automatically by the utility. Am I right?

    opened by redaemn 1
Owner
Sindre Sorhus
Full-Time Open-Sourcerer. Wants more empathy & kindness in open source. Focuses on Swift & JavaScript. Makes macOS apps, CLI tools, npm packages. Likes unicorns
Sindre Sorhus
An async control-flow library that makes stepping through logic easy.

Step A simple control-flow library for node.JS that makes parallel execution, serial execution, and error handling painless. How to install Simply cop

Tim Caswell 2.2k Dec 22, 2022
A solid, fast Promises/A+ and when() implementation, plus other async goodies.

when.js When.js is a rock solid, battle-tested Promises/A+ and when() implementation, including a complete ES6 Promise shim. It's a powerful combinati

The Javascript Architectural Toolkit 3.4k Dec 18, 2022
CSP channels for Javascript (like Clojurescript's core.async, or Go) THIS IS AN UPSTREAM FORK

js-csp Communicating sequential processes for Javascript (like Clojurescript core.async, or Go). Examples var csp = require("js-csp"); Pingpong (porte

James Long 283 Sep 22, 2022
An extension to Async adding better handling of mixed Series / Parallel tasks via object chaining

async-chainable Flow control for NodeJS applications. This builds on the foundations of the Async library while adding better handling of mixed Series

Matt Carter 25 Jul 15, 2019
A workshop about JavaScript iteration protocols: iterator, iterable, async iterator, async iterable

JavaScript Iteration protocol workshop A workshop about JavaScript iteration protocols: iterator, iterable, async iterator, async iterable by @loige.

Luciano Mammino 96 Dec 20, 2022
Parallel/concurrent async work, optionally using multiple threads or processes

parallel-park Parallel/concurrent async work, optionally using multiple processes Usage parallel-park exports two functions: runJobs and inChildProces

Lily Scott 10 Mar 1, 2022
Yet another concurrent priority task queue, yay!

YQueue Yet another concurrent priority task queue, yay! Install npm install yqueue Features Concurrency control Prioritized tasks Error handling for b

null 6 Apr 4, 2022
An iterator wrapper that supports Rust-style chaining

Riter (in development) An iterator wrapper that supports Rust-style chaining Install TODO: This package is not yet available. Once it's mature enough,

잇창명 3 Mar 3, 2022
Utility functions for iterators. Inspired by Rust's `std::iter::Iterator` trait.

iter-funcs About Utility functions for iterators. Inspired by Rust's std::iter::Iterator trait. This library uses JavaScript native iterators, so it's

Shuntaro Nishizawa 6 Dec 27, 2022
FieldVal - multipurpose validation library. Supports both sync and async validation.

FieldVal-JS The FieldVal-JS library allows you to easily validate data and provide readable and structured error reports. Documentation and Examples D

null 137 Sep 24, 2022