zesterer / flume

A safe and fast multi-producer, multi-consumer channel.
https://crates.io/crates/flume
Apache License 2.0
2.37k stars 84 forks source link

Make Selector reusable #39

Open oblique opened 4 years ago

oblique commented 4 years ago

A common pattern is to use Selector in an infinite loop. Now a user need to reconstruct a new Selector in each iteration because wait consumes it. This can have performance impact in high load cases.

Is it possible to make wait borrowing self?

zesterer commented 4 years ago

Yes, in theory. A few changes need to be made to support that use-case, however. I'll add that to my to-do list for the next few days.

saiintbrisson commented 1 year ago

Hi @zesterer! I'm willing to try and work this out. I've checked things here and have a decent idea of how to implement it, but maybe you could give me some directions on what you think should be changed.

I also came up with a sketch of an OwnedSelector that consumes owned receivers instead of references and is able to be stored in structs without needing lifetimes or 'static leakages, but I'm not sure this is desired. This removes the need to box the selection every time the selector is built.

But maybe this could be done by having the channel_macro! do everything on the stack.

zesterer commented 1 year ago

Hi @zesterer! I'm willing to try and work this out. I've checked things here and have a decent idea of how to implement it, but maybe you could give me some directions on what you think should be changed.

I also came up with a sketch of an OwnedSelector that consumes owned receivers instead of references and is able to be stored in structs without needing lifetimes or 'static leakages, but I'm not sure this is desired. This removes the need to box the selection every time the selector is built.

But maybe this could be done by having the channel_macro! do everything on the stack.

Hi, I can definitely see this working out! Did you have more details about what sort of implementation & API you'd likely be looking to go for?