async-interop/event-loop

Multiple read / write watchers on one stream

kelunik opened this issue · 3 comments

Should multiple concurrently enabled read / write watchers on the same stream error? I can't imagine a use case and think it's an error when it happens. Multiple watchers with one enabled at a time might be fine to switch between different handlers.

One problem I can see is that watchers are enabled by default and you can't create a new watcher being disabled if one is enabled already.

It may or may not be an error … perhaps you want to peek onto the stream and log raw stream data and have the other read watcher invoked afterwards.
I'm not fond of prohibiting possible valid uses, just to make the ultra-rare case error when you've accidentally installed two watchers on the same stream (that never happened to me accidentally as far as I can remember).

@bwoebi If you install a second read watcher to consume and log the data, the data will be gone for the second read watcher and things will break.

I said peek, not consume. (e.g. stream_socket_recvfrom() with STREAM_PEEK)