Re:The Problem of Async Programming, and a Crazy Idea for So...
by lorean_victor on Monday December 10, 2018 @07:24PM
(#18652351)
so in your code sample, would 'aOut' be a promise or a value? in case it is a promise, then basically doC() would needed to be re-written to handle when it gets a promised value instead of an actual value, and if not, then doA() must be invoked synchronously, i.e. the `let bOut = doB()` statement must be awaiting `let aOut = doA()` statement which is not what the desired async execution flow is.
Re:The Problem of Async Programming, and a Crazy Idea for So...
by jmull on Monday December 10, 2018 @07:49PM
(#18652473)
Yes, aOut would be a promise. It would look like this:
async function doA() {
...
return "the-result-of-a";
}
(Which returns a promise. Assuming execution reaches that last line of my sample code, the promise will resolve to "the-result-of-a" when you "await" it.)> ...then basically doC() would needed to be re-written to handle when it gets a promised value instead of an actual value
Well, wait a minute... it wasn't written in the first place! Let's write it though. It would look like this:
async function doC( param ) {
...
// we use "await param" where we want to
// access the value of param. e.g.:
const paramValue = await param;
...
}
So not bad.
Re:The Problem of Async Programming, and a Crazy Idea for So...
by lorean_victor on Monday December 10, 2018 @08:02PM
(#18652523)
yeah really not bad at all, didn't think of that solution originally. edited the article accordingly.
With async/await, wouldn't the example just be:
That is, it looks the same as the sync version.The difference is in the "do" functions themselves: they would be async (meaning they return a promise, and they accept promises as parameters).