top | item 46056448

(no title)

jdranczewski | 3 months ago

I may be misunderstanding it, but the examples shown don't seem to be illustrative? It seems reasonably obvious that the prints will happen in this order in any language, because in example 1 we are explicitly (a)waiting for the child to finish, and in example 2 both of the parent prints are above the await. So I don't feel like either of these makes the point the author is trying to get across?

discuss

order

mikkelam|3 months ago

I agree. If you strictly follow the syntax of "Example 1" in JavaScript (calling and awaiting on the same line), the observable output is identical to Python.

I suppose the author meant to say that if you first called your async function and then later did `await` you would have different behavior.

misiek08|3 months ago

In every language having any kind of asynchronous features you should get exactly same result. Other comments already mentioned how the example should look and how it differs.

In short: having other coroutine working and awaiting e.g. on sleep() you can get anything between „parent before” and „child start”. In Python is impossible, because child is not run as new task.