Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

How can this work:

  asyncio.create_task(myfunc())               # Python with asyncio
Surely it would then call `myfunc` in the main thread, block until it be done, then return whatever value it returns if it return at all, and call `create_task` with that value in the event that it return?


IIUC if `myfunc` is an async function, calling it will immediately return a coroutine object.

None of the function’s code will run until it is `await`ed. (Unlike some other languages, async-await in Python is not “synchronous to the first await”.)


It is implied that myfunc returns an awaitable object, not its ultimate result.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: