Convenience method for processing keys from the selected key set.
Convenience method for processing keys from the selected key set.
Pattern matching on the channel type avoids the need for potentially unsafe casting to the channel type you expect.
If a channel type is selected that does not match the pattern match supplied then a defect is raised.
Usage:
for { _ <- selector.select _ <- selector.foreachSelectedKey { key => key.matchChannel { readyOps => { case channel: ServerSocketChannel if readyOps(Operation.Accept) => // use `channel` to accept connection case channel: SocketChannel => IO.when(readyOps(Operation.Read)) { // use `channel` to read } *> IO.when(readyOps(Operation.Write)) { // use `channel` to write } } } } } yield ()
Function that is passed the ready operations set, and must return a partial function that handles whatever channel types are registered with the selector.
The effect value returned by matcher
, or a defect value if matcher
did not match the selected channel.