From e035d86ee0aad045065cda3f7c0836cdb361a5fb Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 22 Sep 2020 19:39:24 +0200 Subject: [PATCH] Added forEachConnection() method to run a function callback against each connection --- src/dorkbox/network/Server.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/dorkbox/network/Server.kt b/src/dorkbox/network/Server.kt index d8b683e0..7808a0bd 100644 --- a/src/dorkbox/network/Server.kt +++ b/src/dorkbox/network/Server.kt @@ -26,9 +26,9 @@ import dorkbox.network.connection.Connection import dorkbox.network.connection.EndPoint import dorkbox.network.connection.ListenerManager import dorkbox.network.connectionType.ConnectionRule +import dorkbox.network.coroutines.SuspendWaiter import dorkbox.network.exceptions.ServerException import dorkbox.network.handshake.ServerHandshake -import dorkbox.network.coroutines.SuspendWaiter import dorkbox.network.rmi.RemoteObject import dorkbox.network.rmi.RemoteObjectStorage import dorkbox.network.rmi.TimeoutException @@ -584,6 +584,15 @@ open class Server(config: ServerConfiguration = ServerC } } + /** + * Execute the unit function against all existing connections + */ + fun forEachConnection(function: (connection: CONNECTION) -> Unit) { + connections.forEach { + function(it) + } + } + /** * Closes the server and all it's connections. After a close, you may call 'bind' again. */