Skip to content

montyanderson/p-for-map

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

p-for-map

Run through a for loop concurrently with Promises.

Usage

// serial

const users = [];

for(let i = 0; i < 10; i++) {
	users[i] = await getUser(i);
}

// concurrent

const users = await pForMap(
	0,
	i => i < 10,
	i => ++i,
	async i => users[i] = await getUser(i)
);

API

pForMap(init, condition, expression, handler)`

Returns a Promise that resolves to the resultant array of values.

init

Type: any
Example: 0

Initial iterator value; what i is set to initially.

condition

Type: Function
Example: i => i < 10

Expected to return a Boolean.

expression

Type: Function
Example: i => ++i

Returns the next i value.

handler

Type: Function
Example: i => console.log(i)

Expected to return a Promise.

About

Run through a for loop concurrently with Promises.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published