@@ -234,9 +234,8 @@ private extension AsyncSocketManager {
234234 }
235235 tasks. removeAll ( keepingCapacity: true )
236236 // sleep
237- if hasEvents == false {
238- try await Task . sleep ( nanoseconds: state. configuration. monitorInterval)
239- }
237+ let sleepInterval = state. configuration. monitorInterval * ( hasEvents ? 1 : 2 )
238+ try await Task . sleep ( nanoseconds: sleepInterval)
240239 }
241240 catch {
242241 log ( " Socket monitoring failed. \( error. localizedDescription) " )
@@ -321,20 +320,17 @@ private extension AsyncSocketManager {
321320 preconditionFailure ( )
322321 continue
323322 }
324- process ( poll, socket: state, tasks: & tasks)
323+ let task = process ( poll, socket: state)
324+ tasks. append ( task)
325325 }
326326 }
327327 return hasEvents
328328 }
329329
330- func process( _ poll: SocketDescriptor . Poll , socket: AsyncSocketManager . SocketState , tasks : inout [ Task < Void , Never > ] ) {
331- let task = Task {
330+ func process( _ poll: SocketDescriptor . Poll , socket: AsyncSocketManager . SocketState ) -> Task < Void , Never > {
331+ Task ( priority : state . configuration . monitorPriority ) {
332332 if poll. returnedEvents. contains ( . read) {
333- if await socket. isListening {
334- await socket. event ( . read, notification: . connection)
335- } else {
336- await socket. event ( . read, notification: . read)
337- }
333+ await socket. event ( . read, notification: socket. isListening ? . connection : . read)
338334 }
339335 if poll. returnedEvents. contains ( . write) {
340336 await socket. event ( . write, notification: . write)
@@ -349,7 +345,6 @@ private extension AsyncSocketManager {
349345 hangup ( poll. socket)
350346 }
351347 }
352- tasks. append ( task)
353348 }
354349
355350 func error( _ error: Errno , for fileDescriptor: SocketDescriptor ) {
0 commit comments