I'm using vibe's websocket handler. It requires a function with the signature void function(scope WebSocket).

I need to receive data from the socket and also wait for events that require me to send data to the socket. This is relatively inconvenient right now. The solution I currently have is to use a thread-safe queue and non-blocking operations and manually yielding -- since there's no way to yield-wait for two things at once.

It would be more straightforward and have less performance overhead to be able to share the socket between several fibers. I can do this today, but that involves casting away scope, which isn't safe.

Is there a better way of doing this?