Skip to content

Commit a38e8dc

Browse files
authored
dont overload async in NIOCompat (#16)
motiavtion: less overloading == less confusion changes: rename async in NIOCompat to eventLoopFuture
1 parent b12bb03 commit a38e8dc

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

Sources/ServiceLauncherNIOCompat/Bridge.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extension Lifecycle.Handler {
2020
///
2121
/// - parameters:
2222
/// - future: the underlying `EventLoopFuture`
23-
public static func async(_ future: @escaping () -> EventLoopFuture<Void>) -> Lifecycle.Handler {
23+
public static func eventLoopFuture(_ future: @escaping () -> EventLoopFuture<Void>) -> Lifecycle.Handler {
2424
return Lifecycle.Handler { callback in
2525
future().whenComplete { result in
2626
switch result {

Tests/ServiceLauncherTests/LifecycleTests.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,14 @@ final class Tests: XCTestCase {
255255
let lifecycle = Lifecycle()
256256

257257
let item1 = NIOItem(eventLoopGroup: eventLoopGroup)
258-
lifecycle.register(name: "item1", start: .async(item1.start), shutdown: .async(item1.shutdown))
258+
lifecycle.register(name: "item1", start: .eventLoopFuture(item1.start), shutdown: .eventLoopFuture(item1.shutdown))
259259

260260
lifecycle.register(name: "blocker",
261261
start: { () -> Void in try eventLoopGroup.next().makeSucceededFuture(()).wait() },
262262
shutdown: { () -> Void in try eventLoopGroup.next().makeSucceededFuture(()).wait() })
263263

264264
let item2 = NIOItem(eventLoopGroup: eventLoopGroup)
265-
lifecycle.register(name: "item2", start: .async(item2.start), shutdown: .async(item2.shutdown))
265+
lifecycle.register(name: "item2", start: .eventLoopFuture(item2.start), shutdown: .eventLoopFuture(item2.shutdown))
266266

267267
lifecycle.start(configuration: .init(shutdownSignal: nil)) { error in
268268
XCTAssertNil(error, "not expecting error")
@@ -434,8 +434,8 @@ final class Tests: XCTestCase {
434434

435435
let item = NIOItem(eventLoopGroup: eventLoopGroup)
436436
lifecycle.register(name: item.id,
437-
start: .async(item.start),
438-
shutdown: .async(item.shutdown))
437+
start: .eventLoopFuture(item.start),
438+
shutdown: .eventLoopFuture(item.shutdown))
439439

440440
lifecycle.start(configuration: .init(shutdownSignal: nil)) { error in
441441
XCTAssertNil(error, "not expecting error")
@@ -450,7 +450,7 @@ final class Tests: XCTestCase {
450450
let lifecycle = Lifecycle()
451451

452452
let item = NIOItem(eventLoopGroup: eventLoopGroup)
453-
lifecycle.registerShutdown(name: item.id, .async(item.shutdown))
453+
lifecycle.registerShutdown(name: item.id, .eventLoopFuture(item.shutdown))
454454

455455
lifecycle.start(configuration: .init(shutdownSignal: nil)) { error in
456456
XCTAssertNil(error, "not expecting error")
@@ -466,11 +466,11 @@ final class Tests: XCTestCase {
466466

467467
let item = NIOItem(eventLoopGroup: eventLoopGroup)
468468
lifecycle.register(name: item.id,
469-
start: .async {
469+
start: .eventLoopFuture {
470470
print("start")
471471
return item.start()
472472
},
473-
shutdown: .async {
473+
shutdown: .eventLoopFuture {
474474
print("shutdown")
475475
return item.shutdown()
476476
})
@@ -488,7 +488,7 @@ final class Tests: XCTestCase {
488488
let lifecycle = Lifecycle()
489489

490490
let item = NIOItem(eventLoopGroup: eventLoopGroup)
491-
lifecycle.registerShutdown(name: item.id, .async {
491+
lifecycle.registerShutdown(name: item.id, .eventLoopFuture {
492492
print("shutdown")
493493
return item.shutdown()
494494
})
@@ -506,8 +506,8 @@ final class Tests: XCTestCase {
506506
let lifecycle = Lifecycle()
507507

508508
lifecycle.register(name: "test",
509-
start: .async { eventLoopGroup.next().makeFailedFuture(TestError()) },
510-
shutdown: .async { eventLoopGroup.next().makeSucceededFuture(()) })
509+
start: .eventLoopFuture { eventLoopGroup.next().makeFailedFuture(TestError()) },
510+
shutdown: .eventLoopFuture { eventLoopGroup.next().makeSucceededFuture(()) })
511511

512512
lifecycle.start(configuration: .init(shutdownSignal: nil)) { error in
513513
XCTAssert(error is TestError, "expected error to match")
@@ -546,12 +546,12 @@ final class Tests: XCTestCase {
546546
let item = Item(expectedData)
547547
let lifecycle = Lifecycle()
548548
lifecycle.register(name: "test",
549-
start: .async {
549+
start: .eventLoopFuture {
550550
item.start().map { data -> Void in
551551
state = .started(data)
552552
}
553553
},
554-
shutdown: .async {
554+
shutdown: .eventLoopFuture {
555555
item.shutdown().map { _ -> Void in
556556
state = .shutdown
557557
}

0 commit comments

Comments
 (0)