Skip to content

A forEach loop for applying asynchronous functions to items in iterable objects

License

Notifications You must be signed in to change notification settings

alex1001xela/forEachAsync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

forEachAsync

A forEach loop for applying asynchronous functions to items in iterable objects

How to use:

forEachAsync ( objectLiteralOrArray, doOnIteration, doAfterLastIteration )

  • objectLiteralOrArray: The object or array you are iterating over
  • doOnIteration ( item, indexOrKey, next )
    • item: the item you want to apply your asynchronous function
    • indexOrKey: the current iteration index or key
    • next (): return this function to move to the next item [1]
  • doAfterLastIteration ()

Notes:

  1. Tail Calls: Returning the next() function is important with ES6. In case you accidentally iterate with a synchronous function over a big iterable, there is a chance that your stack will overflow. That's why tail-calling next() could be important.
    Read more here:
    http://stackoverflow.com/questions/23260390/node-js-tail-call-optimization-possible-or-not
    http://2ality.com/2014/04/call-stack-size.html

About

A forEach loop for applying asynchronous functions to items in iterable objects

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published