If I want users to be able to write their app level protocol handlers as
coroutines, that means I have to use "yield from" everywhere inside my
framework.

No, that doesn't mean that. Did you misunderstand what I wrote?


Alright, I guess I misunderstood what you said.

So you say I call the user-level functions (which may be coroutines) like this from within my protocol implementation?

res = self.onMessage(message)
if PY3 and (isinstance(res, asyncio.futures.Future) or
            inspect.isgenerator(res)):
   asyncio.async(res)

=> onMessage is the user code

This seems to work .. and is far less intrusive!

Now if that is what you meant, could you please confirm?

Also: will asyncio.async schedule via reentering the event loop or how? I am asking since these user-level functions will get called for each and every received WebSocket message .. very often. Any performance caveats?

Thanks so much!

/Tobias

Reply via email to