Hi,
I was playing with async/await and aio in Brython.
I was wondering why executing async functions don't return a Promise instead of having to go to the trouble to use aio.run() to really execute the functions (which seems a quite weird).
Indeed, in Brython, using aio.run() goes against asyncio principles as aio.run() must be executed only once (while in Brython we need to execute it for each call to async function), moreover, Brython does not need an event loop as the browser already have one.
If we wanted to do as asyncio does, shouldn't aio.run() be replaced by aio.create_task() ?
Also, instead of creating a coroutine when an async function is called (which is strange as calling async JS function in Brython does return a Promise), why not executing it normally, and provide 2 ways of using aio.create_task() ?
- aio.create_task( <JS Promise> ) => returns Promise? (do nothing itself)
- aio.create_task( <coroutine> ) => returns Promise?
as well as a function : aio.create_coroutine(fct, arguments) which would enable to create coroutine from Brython but also JS async functions.
What do you think ?
Cordially,