Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced Promise.each with Promise.mapSeries #1081

Merged
merged 1 commit into from Apr 27, 2016

Conversation

aral
Copy link
Contributor

@aral aral commented Apr 27, 2016

The serial version of .map() isn’t .each(), it’s .mapSeries() – i.e., if you want to replace a piece of code that doesn’t fail when certain promises in an array fail but you want to maintain the order of promise execution, you should use .mapSeries().

e.g.,

Promise.map(inspections, ((inspection) -> return inspection().reflect()), {concurrency: 1})
.then (inspection) ->
    console.log "\nResults:\n"
    inspection
.each (inspection) ->
    if inspection.isFulfilled()
        console.log "  ✅  #{inspection.value()}"
    else
        console.log "  ❌  #{inspection.reason().message}"

In the above code, replace .map() with .mapSeries() and you will get the desired effect. Replace it with .each(), as previously suggested and you won’t.

Also removed the broken sentence "This makes sense because the order of the even with the {concurrency: 1}." as it doesn’t make grammatical sense and I’m not sure it adds anything to understanding the problem and find the alternative sooner.

The serial version of map() isn’t each(), it’s mapSeries() – i.e., if you want to replace a piece of code that doesn’t fail when certain promises in an array fail but you want to maintain the order of promise execution, you should use mapSeries().

e.g.,

```
	Promise.map(inspections, ((inspection) -> return inspection().reflect()), {concurrency: 1})
	.then (inspection) ->
		console.log "\nResults:\n"
		inspection
	.each (inspection) ->
		if inspection.isFulfilled()
			console.log "  ✅  #{inspection.value()}"
		else
			console.log "  ❌  #{inspection.reason().message}"
```

In the above code, replace .map() with .mapSeries() and you will get the desired effect. Replace it with .each(), as previously suggested and you won’t.

Also removed the broken sentence "This makes sense because the order of the even with the `{concurrency: 1}`." as it doesn’t make grammatical sense and I’m not sure it adds anything to understanding the problem and find the alternative sooner.
@petkaantonov petkaantonov merged commit 067fa93 into petkaantonov:master Apr 27, 2016
@aral aral deleted the patch-1 branch April 27, 2016 13:40
@aral
Copy link
Contributor Author

aral commented Apr 27, 2016

Thanks, Petka :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants