| ▲ | throwup238 7 hours ago | |||||||||||||||||||
So do Python and Javascript. I think most languages with async/await also support noop-ing the yield if the future is already resolved. It’s only when you create a new task/promise that stuff is guaranteed to get scheduled instead of possibly running immediately. | ||||||||||||||||||||
| ▲ | amluto 5 hours ago | parent [-] | |||||||||||||||||||
I can't quite parse what you're saying. Python works like this:
Running it does this:
So there mere act of creating a coroutine does not cause the runtime to run it. But if you explicitly create a task, it does get run:
I personally like the behavior of coroutines not running unless you tell them to run -- it makes it easier to reason about what code runs when. But I do not particularly like the way that Python obscures the difference between a future-like thing that is a coroutine and a future-like thing that is a task. | ||||||||||||||||||||
| ||||||||||||||||||||