Return Promise if callback is not provided?
See original GitHub issueNice to have in ES2017 async/await development
const asyncjs = require('async');
const foo = async () => {
const arr = Array.from({ length: 1000 }, (v, i) => i);
const transformedArr = await asyncjs.mapLimit(arr, 100, async (v) => {
return await Promise.resolve(v * 2);
});
console.log(transformedArr);
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:27
- Comments:8
Top Results From Across the Web
How to make a function return a promise if optional callback is ...
You can do it like so: function squareAsync(val, callback) { const timeout = function(res, rej){ setTimeout(function(){ if (Math.random() ...
Read more >How to make a Promise out of a Callback function in JavaScript
Solution 2 (involved): Turn the Callback into a Promise. Sometimes, using the request and util libraries is just not possible, whether it's ...
Read more >Using promises - JavaScript - MDN Web Docs
Essentially, a promise is a returned object to which you attach callbacks, instead of passing callbacks into a function.
Read more >Converting Callbacks to Promises in Node.js - Stack Abuse
Let's talk about how to covert callbacks to promises if the util.promisify() function is not available. The idea is to create a new...
Read more >25. Promises for asynchronous programming - Exploring JS
Promises provide a better way of working with callbacks: Now an asynchronous function returns a Promise, an object that serves as a placeholder...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve thought about this, and experimented with it a bit. People are going to want to
await Async.mapLimit(arr, 10, async foo => {...})
. It could very well be something we include in 3.0.Also, some Async methods would be pretty silly with async/await, e.g.
series
,waterfall
.@tritoanst, your promisify function is overhead. It may be easier: