4 ms·
> How do you know how to call that function? async def foo() is not a function and it doesn't have the same signature: the async is very explicit. It's a diff
by BiteCode_dev 6y ago
> How do you know how to call that function?
async def foo() is not a function and it doesn't have the same signature: the async is very explicit.
It's a different primitive, and it's not used AT ALL for the same thing at a function.
It's like writting:
def foo():
yield "bar"
and saying, 'how do you cal that function? How do you know how to call that function? It's called the same thing. It has the same signature.. It returns the same thing. One has one exit point, the other has several. This is "colored functions".
You have to call the 2nd one like:
next(iter(foo()))
It's absurd'
Well, no, it's not. It's a different tool. It's not a function, it's a generator.
You don't have to care about async/await. In fact, you can live your entire life without using them.
But it's a handy tool that allows you do:
- delegate asynchronous behavior, like I/O, outside of your callable
- make you match the syntaxic order with execution order despite said delegation
- make it clear and explicit where you chose to do so, indentifying the context switching of your program
Does it seems complicated ? It's because it is, and you probably don't need it.
But if you need it, it's easier than the alternative of using callbacks, and less error prones that implicit asyncronicity.