-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #117 from theleftbit/task-never
Welcome Task.Never
- Loading branch information
Showing
3 changed files
with
26 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |