async-interop / event-loop

An event loop interface for interoperability in PHP.
MIT License
170 stars 9 forks source link

Multiple read / write watchers on one stream #152

Open kelunik opened 7 years ago

kelunik commented 7 years ago

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.

bwoebi commented 7 years ago

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).

kelunik commented 7 years ago

@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.

bwoebi commented 7 years ago

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