So, this started out as a practical problem, but now it's more curiosity. 

Cap'n Proto uses an event loop for concurrency. I'm using another library 
that has its *own* event loop for concurrency. They refuse to use each 
other's event loops. Although the basic logic is the same between the two, 
the APIs are incompatible. 

So, how do I mix two event loops?

My thought was, that if one of the event loops supports a callback when an 
event is queued I can essentially use one event loop to drive the other.

The basic logic would be something like the following (Python syntax, but 
you get the idea):

loop1 = cnp_event_loop()
loop2 = some_other_lib_event_loop()

@loop1.on_event_added
def _():
    @loop2.call_soon
    def _():
        loop1.poll()

def adapt_future(f):
    f2 = loop2.create_future()
    if f.done():
        f2.set_result(f.result())
    else:
        @f.add_done_callback
        def _():
            f2.set_result(f.result())
    return f2

async def main():
    res = await adapt_future(func_that_returns_a_cnp_promise())
    print(res)

loop2.run_until_complete(main2())

(The function Cap'n Proto doesn't support is on_event_added() on an 
EventLoop.)

Just curious if anyone has any thoughts on this. 

-- 
You received this message because you are subscribed to the Google Groups 
"Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/capnproto/7b46e93a-a42e-4f69-b5f5-f924a3b81550n%40googlegroups.com.

Reply via email to