Skip to content

Commit

Permalink
Merge pull request #3 from Fred78290/close-future
Browse files Browse the repository at this point in the history
Expose closeFuture
  • Loading branch information
Fred78290 authored Dec 17, 2024
2 parents 8b39709 + b8cab34 commit de4327d
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions Sources/Lib/Forwarder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,27 @@ public struct PortForwarderClosure {
let channels : [EventLoopFuture<Channel>]
private let on: EventLoop

public var closeFuture: EventLoopFuture<Void> {
get {
return EventLoopFuture.andAllComplete(self.channels.map { future in
future.flatMap { channel in
channel.closeFuture
}
}, on: on)
}
}

init(_ channels: [EventLoopFuture<Channel>], on: EventLoop) {
self.channels = channels
self.on = on
}

public func get() async throws {
let closing = self.channels.map { future in
future.flatMap { channel in
channel.closeFuture
}
}

try await EventLoopFuture.andAllComplete(closing, on: on).get()
try await self.closeFuture.get()
}

public func wait() throws {
let closing = self.channels.map { future in
future.flatMap { channel in
channel.closeFuture
}
}

try EventLoopFuture.andAllComplete(closing, on: on).wait()
try self.closeFuture.wait()
}
}

Expand Down

0 comments on commit de4327d

Please sign in to comment.