diff --git a/zio-http/src/main/scala/zio/http/Channel.scala b/zio-http/src/main/scala/zio/http/Channel.scala index 9a4e405d0c..4ec514f56a 100644 --- a/zio-http/src/main/scala/zio/http/Channel.scala +++ b/zio-http/src/main/scala/zio/http/Channel.scala @@ -40,6 +40,11 @@ trait Channel[-In, +Out] { self => */ def send(in: In): Task[Unit] + /** + * Send all messages to the channel. + */ + def sendAll(in: Iterable[In]): Task[Unit] + /** * Shut down the channel. */ @@ -57,6 +62,8 @@ trait Channel[-In, +Out] { self => self.receive def send(in: In2): Task[Unit] = self.send(f(in)) + def sendAll(in: Iterable[In2]): Task[Unit] = + self.sendAll(in.map(f)) def shutdown: UIO[Unit] = self.shutdown } @@ -73,6 +80,8 @@ trait Channel[-In, +Out] { self => self.receive.map(f) def send(in: In): Task[Unit] = self.send(in) + def sendAll(in: Iterable[In]): Task[Unit] = + self.sendAll(in) def shutdown: UIO[Unit] = self.shutdown } diff --git a/zio-http/src/main/scala/zio/http/WebSocketChannel.scala b/zio-http/src/main/scala/zio/http/WebSocketChannel.scala index 8823e3a319..50962dc110 100644 --- a/zio-http/src/main/scala/zio/http/WebSocketChannel.scala +++ b/zio-http/src/main/scala/zio/http/WebSocketChannel.scala @@ -40,6 +40,11 @@ private[http] object WebSocketChannel { case Read(message) => nettyChannel.writeAndFlush(frameToNetty(message)) case _ => ZIO.unit } + def sendAll(in: Iterable[WebSocketChannelEvent]): Task[Unit] = + ZIO.foreachDiscard(in) { + case Read(message) => nettyChannel.write(frameToNetty(message)) + case _ => ZIO.unit + } *> nettyChannel.flush def shutdown: UIO[Unit] = nettyChannel.close(false).orDie }