Skip to content

Commit

Permalink
Merge pull request #117 from theleftbit/task-never
Browse files Browse the repository at this point in the history
Welcome Task.Never
  • Loading branch information
piercifani authored Jan 25, 2022
2 parents 9359b68 + 3cff333 commit bc6c588
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public func bothSerially<T, U>(first: Task<T>, second: @escaping (T) -> Task<U>)
deferred.fill(with: .success((firstValue, secondValue)))
}
}

return Task(Future(deferred))
}

Expand Down
9 changes: 9 additions & 0 deletions Sources/BSWFoundation/Extensions/Task.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

public extension Task where Success == Never, Failure == Never {
/// Returns a Task that will never return... Well, actually, it'll complete in 1000 seconds
static var never: Void {
get async throws {
try await Task.sleep(nanoseconds: 1_000_000_000_000)
}
}
}
17 changes: 17 additions & 0 deletions Tests/BSWFoundationTests/Extensions/TaskTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

import XCTest
import BSWFoundation

class TaskTests: XCTestCase {
func testNever() async throws {
let waiter = XCTWaiter()
let exp = self.expectation(description: " ")
let task = Task(priority: .userInitiated) {
let _ = try await Task.never
exp.fulfill()
}
waiter.wait(for: [exp], timeout: 1)
XCTAssert(waiter.fulfilledExpectations.isEmpty)
task.cancel()
}
}

0 comments on commit bc6c588

Please sign in to comment.