// This must be called on the libuv event loop public void WalkConnectionsAndClose() { if (_connectionStopTasks != null) { throw new InvalidOperationException($"{nameof(WalkConnectionsAndClose)} cannot be called twice."); } _connectionStopTasks = new List <Task>(); _thread.Walk(ptr => { var handle = UvMemory.FromIntPtr <UvHandle>(ptr); var connection = (handle as UvStreamHandle)?.Connection; if (connection != null) { _connectionStopTasks.Add(connection.StopAsync()); } }); }
private void WalkConnectionsAndCloseCore(TaskCompletionSource <object> tcs) { var connectionStopTasks = new List <Task>(); _thread.Walk(ptr => { var handle = UvMemory.FromIntPtr <UvHandle>(ptr); var connection = (handle as UvStreamHandle)?.Connection; if (connection != null) { connectionStopTasks.Add(connection.StopAsync()); } }); _threadPool.Run(() => { Task.WaitAll(connectionStopTasks.ToArray()); tcs.SetResult(null); }); }