flexx icon indicating copy to clipboard operation
flexx copied to clipboard

Allow using cocoutines (and await) in actions

Open almarklein opened this issue 8 years ago • 2 comments

In #408 we base the event loop on asyncio, which opens up the possibility to use async and await in tests. At this point, we cannot write actions or reactions as co-routines. Reactions can probably not be co-routines, since the state needs to be constant while processing (a batch of) reactions. But we can probably allow actions to be co-routines.

Implementation-wise, the event system will need to check whether an action-function is actually a co-routine and pass it to asyncio if it is. This will only work for PyComponents, unless we add some sort of async support to pyscript.

Then we can make use of tools from aio-libs, like aiohttp.

almarklein avatar Nov 24 '17 10:11 almarklein

I think it makes the most sense to use async io in PyComponent actions anyway!

Korijn avatar Nov 24 '17 12:11 Korijn

PScript just got support for async and await. It works fine for JS apps, but probably not yet at the Python side.

Calling an async function in JS returns a Promise, and the promise will always run, whether the caller awaits it or not. On Python this is not the case; a co-routine is returned, which won't do anything unless its run in some way.

almarklein avatar Aug 10 '18 23:08 almarklein