Skip to content

Commit 8f61d72

Browse files
authored
Add some NIO sugar to ServiceLifecycle.start() (#72)
1 parent c8e9952 commit 8f61d72

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Sources/LifecycleNIOCompat/Bridge.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,22 @@ extension LifecycleHandler {
4646
}
4747
}
4848
}
49+
50+
extension ServiceLifecycle {
51+
/// Starts the provided `LifecycleItem` array.
52+
/// Startup is performed in the order of items provided.
53+
///
54+
/// - parameters:
55+
/// - eventLoop: The `eventLoop` which is used to generate the `EventLoopFuture` that is returned. After the start the future is fulfilled:
56+
func start(on eventLoop: EventLoop) -> EventLoopFuture<Void> {
57+
let promise = eventLoop.makePromise(of: Void.self)
58+
self.start { error in
59+
if let error = error {
60+
promise.fail(error)
61+
} else {
62+
promise.succeed(())
63+
}
64+
}
65+
return promise.futureResult
66+
}
67+
}

0 commit comments

Comments
 (0)