How to use multiple event loop togather?

in my case I have to event loops, one from notify, and the other from a 2d drawing library. I could handle very simple case if both of them use channels like:

loop {
  a.try_recv()
  b.try_recv()

 // sleep for a while
}

but as I looked into winit, piston, sdl2.. I see many of them use iterators, which makes its event loop hard to cooperate with a channel. and winit internally uses a callback on macos which makes it even harder().

I also thought about moving my notify code into the closure of UI event loop, but a lot of variables can not be moved in a simple way. So I don't know if that's viable as well...

thought for a while of turning the iterator into a channel, but how about threads, and the types of channels? still unclear...

is there a clear way of common pattern in solving this? or which 2d library plus window library should I use in such a case?

It sounds like you should probably spawn a thread for each.

1 Like

You could try crossbeam select!().

2 Likes

finally made it work, but in a dirty solution, based on a breaking(kind of... on macos) API event_loop.run_return(...):