What is the difference between async.map from async library and Promise.map from bluebird?Difference between == and === in JavaScriptWhat's the difference between using “let” and “var”?What is the difference between call and apply?What is the difference between substr and substring?What is the difference between null and undefined in JavaScript?Differences between lodash and underscoreWhat is the difference between Bower and npm?What's the difference between dependencies, devDependencies and peerDependencies in npm package.json file?What's the difference between tilde(~) and caret(^) in package.json?Why do we need middleware for async flow in Redux?
Why not increase contact surface when reentering the atmosphere?
What happens if you roll doubles 3 times then land on "Go to jail?"
What Brexit proposals are on the table in the indicative votes on the 27th of March 2019?
Are student evaluations of teaching assistants read by others in the faculty?
Why escape if the_content isnt?
Why, precisely, is argon used in neutrino experiments?
A particular customize with green line and letters for subfloat
Trouble understanding the speech of overseas colleagues
How long to clear the 'suck zone' of a turbofan after start is initiated?
What is the best translation for "slot" in the context of multiplayer video games?
How do I go from 300 unfinished/half written blog posts, to published posts?
Unreliable Magic - Is it worth it?
How to Reset Passwords on Multiple Websites Easily?
Is there a good way to store credentials outside of a password manager?
How to pronounce the slash sign
Gears on left are inverse to gears on right?
Applicability of Single Responsibility Principle
Was Spock the First Vulcan in Starfleet?
Tiptoe or tiphoof? Adjusting words to better fit fantasy races
Pole-zeros of a real-valued causal FIR system
Fastening aluminum fascia to wooden subfascia
What is the difference between "behavior" and "behaviour"?
Purchasing a ticket for someone else in another country?
CREATE opcode: what does it really do?
What is the difference between async.map from async library and Promise.map from bluebird?
Difference between == and === in JavaScriptWhat's the difference between using “let” and “var”?What is the difference between call and apply?What is the difference between substr and substring?What is the difference between null and undefined in JavaScript?Differences between lodash and underscoreWhat is the difference between Bower and npm?What's the difference between dependencies, devDependencies and peerDependencies in npm package.json file?What's the difference between tilde(~) and caret(^) in package.json?Why do we need middleware for async flow in Redux?
I explain myself:
What I want to do is using async/await with one of those library (async or bluebird).
I don't understand why this works well:
const promises = Promise.map (someArray, async item =>
const result = await getSomething(item);
return ...item, ...result
);
const promisesResults = await Promise.all(promises);
But the same with async.map doesn't. It returns me undefined.
Thanks everyone!
javascript node.js async-await bluebird async.js
add a comment |
I explain myself:
What I want to do is using async/await with one of those library (async or bluebird).
I don't understand why this works well:
const promises = Promise.map (someArray, async item =>
const result = await getSomething(item);
return ...item, ...result
);
const promisesResults = await Promise.all(promises);
But the same with async.map doesn't. It returns me undefined.
Thanks everyone!
javascript node.js async-await bluebird async.js
But the same with async.map doesn't. - it can't be the same because it's different library. What code exactly do you try?
– estus
Mar 7 at 12:55
const promises = async.map (someArray, async item => const result = await getSomething(item); return ...item, ...interview );
– samteb
Mar 7 at 13:02
add a comment |
I explain myself:
What I want to do is using async/await with one of those library (async or bluebird).
I don't understand why this works well:
const promises = Promise.map (someArray, async item =>
const result = await getSomething(item);
return ...item, ...result
);
const promisesResults = await Promise.all(promises);
But the same with async.map doesn't. It returns me undefined.
Thanks everyone!
javascript node.js async-await bluebird async.js
I explain myself:
What I want to do is using async/await with one of those library (async or bluebird).
I don't understand why this works well:
const promises = Promise.map (someArray, async item =>
const result = await getSomething(item);
return ...item, ...result
);
const promisesResults = await Promise.all(promises);
But the same with async.map doesn't. It returns me undefined.
Thanks everyone!
javascript node.js async-await bluebird async.js
javascript node.js async-await bluebird async.js
edited Mar 7 at 13:16
samteb
asked Mar 7 at 12:48
samtebsamteb
187
187
But the same with async.map doesn't. - it can't be the same because it's different library. What code exactly do you try?
– estus
Mar 7 at 12:55
const promises = async.map (someArray, async item => const result = await getSomething(item); return ...item, ...interview );
– samteb
Mar 7 at 13:02
add a comment |
But the same with async.map doesn't. - it can't be the same because it's different library. What code exactly do you try?
– estus
Mar 7 at 12:55
const promises = async.map (someArray, async item => const result = await getSomething(item); return ...item, ...interview );
– samteb
Mar 7 at 13:02
But the same with async.map doesn't. - it can't be the same because it's different library. What code exactly do you try?
– estus
Mar 7 at 12:55
But the same with async.map doesn't. - it can't be the same because it's different library. What code exactly do you try?
– estus
Mar 7 at 12:55
const promises = async.map (someArray, async item => const result = await getSomething(item); return ...item, ...interview );– samteb
Mar 7 at 13:02
const promises = async.map (someArray, async item => const result = await getSomething(item); return ...item, ...interview );– samteb
Mar 7 at 13:02
add a comment |
1 Answer
1
active
oldest
votes
async is legacy library that solved same problems as promises before the propagation of promise pattern and the emergence of native promises. async library is callback-based and is unaware of promises and async functions, which are syntactic sugar for ES6 promises.
The snippet works because Promise.all expects an array of promises:
Promise.all(promises);
And an array of promises is provided with array map with async function callback:
someArray.map(async item => ... )
This won't work with async library because it's supposed to work with callback-based iteratee function and is unaware of promises that async function returns.
Since ES6 promises lack some advanced features from async library, they can be augmented with Bluebird API or promise ponyfills.
I understand! So if I want to use async/await and Promise.all it is better to use bluebird library right ?
– samteb
Mar 7 at 13:10
Yes, you don't needasynclib when you work with promises. You may not need Bluebird too ifPromise.allis all you need.someArray.mapcode you originally posted would work with ES6 promises alone. You may take a look at promise ponyfills which offer most things that Bluebird does to not depend on the whole Bluebird library.
– estus
Mar 7 at 13:13
I use a lotPromise.allin my project and I read that to avoid creating an array of promises every time I can easily use` Promise.map` from bluebird. I am gonna take look atponyfills. And tell me what about performance ? async or bluebird ?
– samteb
Mar 7 at 13:19
If you don't need temp variable you can skip it, it's as simple asPromise.all(someArray.map(async item => ... )). Pure Bluebird promise chain is faster than pure native promise chain (may change in future) but most performance improvements are discarded sinceasyncuses native promises any way. I'd say the performance is not a reason to choose Bluebird here. As forasynclibrary, I didn't measure but promises are fast enough to not bother with premature optimization.
– estus
Mar 7 at 13:29
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55044185%2fwhat-is-the-difference-between-async-map-from-async-library-and-promise-map-from%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
async is legacy library that solved same problems as promises before the propagation of promise pattern and the emergence of native promises. async library is callback-based and is unaware of promises and async functions, which are syntactic sugar for ES6 promises.
The snippet works because Promise.all expects an array of promises:
Promise.all(promises);
And an array of promises is provided with array map with async function callback:
someArray.map(async item => ... )
This won't work with async library because it's supposed to work with callback-based iteratee function and is unaware of promises that async function returns.
Since ES6 promises lack some advanced features from async library, they can be augmented with Bluebird API or promise ponyfills.
I understand! So if I want to use async/await and Promise.all it is better to use bluebird library right ?
– samteb
Mar 7 at 13:10
Yes, you don't needasynclib when you work with promises. You may not need Bluebird too ifPromise.allis all you need.someArray.mapcode you originally posted would work with ES6 promises alone. You may take a look at promise ponyfills which offer most things that Bluebird does to not depend on the whole Bluebird library.
– estus
Mar 7 at 13:13
I use a lotPromise.allin my project and I read that to avoid creating an array of promises every time I can easily use` Promise.map` from bluebird. I am gonna take look atponyfills. And tell me what about performance ? async or bluebird ?
– samteb
Mar 7 at 13:19
If you don't need temp variable you can skip it, it's as simple asPromise.all(someArray.map(async item => ... )). Pure Bluebird promise chain is faster than pure native promise chain (may change in future) but most performance improvements are discarded sinceasyncuses native promises any way. I'd say the performance is not a reason to choose Bluebird here. As forasynclibrary, I didn't measure but promises are fast enough to not bother with premature optimization.
– estus
Mar 7 at 13:29
add a comment |
async is legacy library that solved same problems as promises before the propagation of promise pattern and the emergence of native promises. async library is callback-based and is unaware of promises and async functions, which are syntactic sugar for ES6 promises.
The snippet works because Promise.all expects an array of promises:
Promise.all(promises);
And an array of promises is provided with array map with async function callback:
someArray.map(async item => ... )
This won't work with async library because it's supposed to work with callback-based iteratee function and is unaware of promises that async function returns.
Since ES6 promises lack some advanced features from async library, they can be augmented with Bluebird API or promise ponyfills.
I understand! So if I want to use async/await and Promise.all it is better to use bluebird library right ?
– samteb
Mar 7 at 13:10
Yes, you don't needasynclib when you work with promises. You may not need Bluebird too ifPromise.allis all you need.someArray.mapcode you originally posted would work with ES6 promises alone. You may take a look at promise ponyfills which offer most things that Bluebird does to not depend on the whole Bluebird library.
– estus
Mar 7 at 13:13
I use a lotPromise.allin my project and I read that to avoid creating an array of promises every time I can easily use` Promise.map` from bluebird. I am gonna take look atponyfills. And tell me what about performance ? async or bluebird ?
– samteb
Mar 7 at 13:19
If you don't need temp variable you can skip it, it's as simple asPromise.all(someArray.map(async item => ... )). Pure Bluebird promise chain is faster than pure native promise chain (may change in future) but most performance improvements are discarded sinceasyncuses native promises any way. I'd say the performance is not a reason to choose Bluebird here. As forasynclibrary, I didn't measure but promises are fast enough to not bother with premature optimization.
– estus
Mar 7 at 13:29
add a comment |
async is legacy library that solved same problems as promises before the propagation of promise pattern and the emergence of native promises. async library is callback-based and is unaware of promises and async functions, which are syntactic sugar for ES6 promises.
The snippet works because Promise.all expects an array of promises:
Promise.all(promises);
And an array of promises is provided with array map with async function callback:
someArray.map(async item => ... )
This won't work with async library because it's supposed to work with callback-based iteratee function and is unaware of promises that async function returns.
Since ES6 promises lack some advanced features from async library, they can be augmented with Bluebird API or promise ponyfills.
async is legacy library that solved same problems as promises before the propagation of promise pattern and the emergence of native promises. async library is callback-based and is unaware of promises and async functions, which are syntactic sugar for ES6 promises.
The snippet works because Promise.all expects an array of promises:
Promise.all(promises);
And an array of promises is provided with array map with async function callback:
someArray.map(async item => ... )
This won't work with async library because it's supposed to work with callback-based iteratee function and is unaware of promises that async function returns.
Since ES6 promises lack some advanced features from async library, they can be augmented with Bluebird API or promise ponyfills.
edited Mar 7 at 13:08
answered Mar 7 at 13:02
estusestus
77.4k23114234
77.4k23114234
I understand! So if I want to use async/await and Promise.all it is better to use bluebird library right ?
– samteb
Mar 7 at 13:10
Yes, you don't needasynclib when you work with promises. You may not need Bluebird too ifPromise.allis all you need.someArray.mapcode you originally posted would work with ES6 promises alone. You may take a look at promise ponyfills which offer most things that Bluebird does to not depend on the whole Bluebird library.
– estus
Mar 7 at 13:13
I use a lotPromise.allin my project and I read that to avoid creating an array of promises every time I can easily use` Promise.map` from bluebird. I am gonna take look atponyfills. And tell me what about performance ? async or bluebird ?
– samteb
Mar 7 at 13:19
If you don't need temp variable you can skip it, it's as simple asPromise.all(someArray.map(async item => ... )). Pure Bluebird promise chain is faster than pure native promise chain (may change in future) but most performance improvements are discarded sinceasyncuses native promises any way. I'd say the performance is not a reason to choose Bluebird here. As forasynclibrary, I didn't measure but promises are fast enough to not bother with premature optimization.
– estus
Mar 7 at 13:29
add a comment |
I understand! So if I want to use async/await and Promise.all it is better to use bluebird library right ?
– samteb
Mar 7 at 13:10
Yes, you don't needasynclib when you work with promises. You may not need Bluebird too ifPromise.allis all you need.someArray.mapcode you originally posted would work with ES6 promises alone. You may take a look at promise ponyfills which offer most things that Bluebird does to not depend on the whole Bluebird library.
– estus
Mar 7 at 13:13
I use a lotPromise.allin my project and I read that to avoid creating an array of promises every time I can easily use` Promise.map` from bluebird. I am gonna take look atponyfills. And tell me what about performance ? async or bluebird ?
– samteb
Mar 7 at 13:19
If you don't need temp variable you can skip it, it's as simple asPromise.all(someArray.map(async item => ... )). Pure Bluebird promise chain is faster than pure native promise chain (may change in future) but most performance improvements are discarded sinceasyncuses native promises any way. I'd say the performance is not a reason to choose Bluebird here. As forasynclibrary, I didn't measure but promises are fast enough to not bother with premature optimization.
– estus
Mar 7 at 13:29
I understand! So if I want to use async/await and Promise.all it is better to use bluebird library right ?
– samteb
Mar 7 at 13:10
I understand! So if I want to use async/await and Promise.all it is better to use bluebird library right ?
– samteb
Mar 7 at 13:10
Yes, you don't need
async lib when you work with promises. You may not need Bluebird too if Promise.all is all you need. someArray.map code you originally posted would work with ES6 promises alone. You may take a look at promise ponyfills which offer most things that Bluebird does to not depend on the whole Bluebird library.– estus
Mar 7 at 13:13
Yes, you don't need
async lib when you work with promises. You may not need Bluebird too if Promise.all is all you need. someArray.map code you originally posted would work with ES6 promises alone. You may take a look at promise ponyfills which offer most things that Bluebird does to not depend on the whole Bluebird library.– estus
Mar 7 at 13:13
I use a lot
Promise.all in my project and I read that to avoid creating an array of promises every time I can easily use` Promise.map` from bluebird. I am gonna take look at ponyfills. And tell me what about performance ? async or bluebird ?– samteb
Mar 7 at 13:19
I use a lot
Promise.all in my project and I read that to avoid creating an array of promises every time I can easily use` Promise.map` from bluebird. I am gonna take look at ponyfills. And tell me what about performance ? async or bluebird ?– samteb
Mar 7 at 13:19
If you don't need temp variable you can skip it, it's as simple as
Promise.all(someArray.map(async item => ... )). Pure Bluebird promise chain is faster than pure native promise chain (may change in future) but most performance improvements are discarded since async uses native promises any way. I'd say the performance is not a reason to choose Bluebird here. As for async library, I didn't measure but promises are fast enough to not bother with premature optimization.– estus
Mar 7 at 13:29
If you don't need temp variable you can skip it, it's as simple as
Promise.all(someArray.map(async item => ... )). Pure Bluebird promise chain is faster than pure native promise chain (may change in future) but most performance improvements are discarded since async uses native promises any way. I'd say the performance is not a reason to choose Bluebird here. As for async library, I didn't measure but promises are fast enough to not bother with premature optimization.– estus
Mar 7 at 13:29
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55044185%2fwhat-is-the-difference-between-async-map-from-async-library-and-promise-map-from%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
But the same with async.map doesn't. - it can't be the same because it's different library. What code exactly do you try?
– estus
Mar 7 at 12:55
const promises = async.map (someArray, async item => const result = await getSomething(item); return ...item, ...interview );– samteb
Mar 7 at 13:02