Enable async/await to work on functions that don't just return promises.
Codefined
codefined at debenclipper.com
Sun Feb 26 17:11:50 UTC 2017
A very interesting read indeed Alexander! Gave me a new example to give when people ask what the worst code I'd ever seen was:
Promise<void> DoSomething(Promise<string> cmd) { return cmd.WhenResolved( s => { if (s == "...") { return DoSomethingElse(...).WhenResolved( v => { return ...; }, e => { Log(e); throw e; } ); } else { return ...; } }, e => { Log(e); throw e; } ); }
My question is however, that this article defines that an `await` keyword must be within an `async` function, which seems an interesting choice to me. For example, the following code snippet:
function callee() { let x = await someAsync(); }
Should `callee()` be asynchronous here? To my mind, no, it shouldn't. Every single line here is synchronous, so the function itself should surely be synchronous. Shouldn't functions that may not have `await` in them, but instead that are actually asynchronous and hence use the `async return` keyword be the ones we define with `async`?
Although, saying that, I think I may steal their use of `async Bar()` when calling functions and add it to the proposal. It makes sense to me that `let x = someAsync()` should error out to let developers know they're doing something wrong. `let x = async someAsync()` clearly does show that they know the function is async and will return a promise..
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170226/c1dc8b7c/attachment-0001.html>
More information about the es-discuss
mailing list