-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
async
Function Support
#1386
Comments
I'm going to ponder over this some more but I'd like to ask a couple technical questions just so I can try to better envision what this looks like.. Is there a reason to do So is the proposal any time someone provides a callback of the format Also sorry, I'm not following on the await example, if we detect that the function is an |
Thats just the canonical ECMA spec way to do it. I guess in theory, someone could overwrite
I think you have it a bit backwards. Wherever we accept an callback-accepting iteratee function ( The |
Implemented in #1390 ! |
This was a breaking change and broke our deployed code. Please think twice when doing such things without increasing the major version. PS: thanks for all the great work you're doing with this library 😄 |
Shoot! What broke. Could you please create a ticket with details of the
environment this didn't work in?
Thanks!
…On Wed, Apr 5, 2017 at 10:18 AM Manuel Valls Fernández < ***@***.***> wrote:
This was a breaking change and broke our deployed code. Please think twice
when doing such things without increasing the major version.
PS: thanks for all the great work you're doing with this library 😄
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1386 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ADUIEPNkTSOVuuiwucBVrH983X6B568Wks5rs6K3gaJpZM4Mf64R>
.
|
Agreed, it broke my build too... A waterfall that was calling an async function which worked a few days back started failing with a "cb is not function" because the async callback was no longer provided to the function. |
Sorry we broke your code. We didn't anticipate your use case for |
@aearly Please, don't mention it!! It's really nice of you to answer 🥇 @manvalls hinted me a great solution which did not require to rollback. As you're using the symbol to detect the My waterfall was using functions exported from other modules, one of them was an So just by changing from: ...
/* services module */
function doThis(param, cb) {
...
}
async function doThatAsync(param, cb) {
...
}
module.exports = {
doThis: doThis,
doThat: doThatAsync
};
...
async.waterfall([
services.doThis,
services.doThat, // fails with "cb is not a function"
], err => {
...
} To: ...
/* services module */
function doThis(param, cb) {
...
}
async function doThatAsync(param, cb) {
...
}
module.exports = {
doThis: doThis,
doThat: (...args) => doThatAsync(..args) // cheating the detection
};
...
async.waterfall([
services.doThis,
services.doThat, /* it works!!! */
], err => {
...
} Thank you very much again |
can we use async/await with async.autoInject()? async.autoInject({
conn1: async function () {
return conn1;
},
conn2: async function () {
return conn2;
},
}); doesn't seem to work, I get:
|
@ORESoftware yes, async.autoInject({
conn1: async function () {
return 'foo'
},
conn2: async function () {
return 'bar'
},
}) it works fine. However, we don't support transpiled |
One of the elephants in the room is the new
async
/await
support that has come to Node and Chrome, and will soon hit every other major browser. I've been thinking about what Async can do in theasync
/await
world.Currently, we can adapt
async
functions by wrapping them withasyncify
. Since anasync
function is essentially just a function that returns a Promise, that old adapter can easily convert it to a callback-style function. However, it leads to the somewhat absurd looking:However, one of the features in the spec for
async
functions is that:This gives a way to easily detect (native)
async
functions. We could use this technique to automaticallyasyncify
them. The example above becomes:...which seems to flow much more naturally. I also think we should continue to use callbacks. If a user wanted to
await
the result, they would have topromisify
the function, orpify
Async as a whole:The above method for detecting
async
functions only works with native functions. I don't think there is a way to detect Babel transpiled functions. We certainly can't detect normal functions that simply return Promises, because we'd have to retroactively not pass a callback. There would he a huge caveat that this would only work without a transpiler in very modern environments, otherwise you still have to manually wrap withasyncify
.Also, admittedly, many Async methods don't make sense with
async
/await
. Most of the control flow methods (save for things likeauto
andqueue
) are more easily replicated with native control flow constructs.map
andparallel
can be replaced withPromise.map
andPromise.all
. However, the limiting collection functions would be very useful, as well asauto
and a few others. (Also,autoInject
withasync
functions is a async control flow dream!)The text was updated successfully, but these errors were encountered: