Skip to content

Commit

Permalink
Use newer Task sleep API
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Sep 22, 2023
1 parent 0c9ecd6 commit b465d96
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions Tests/QueueTests/AsyncQueueTests.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import XCTest
import Queue

extension Task where Success == Never, Failure == Never {
static func sleep(milliseconds: UInt64) async throws {
try await sleep(for: .milliseconds(milliseconds))
}
}

enum QueueTestError: Error, Hashable {
case operatorFailure
}
Expand Down Expand Up @@ -78,7 +72,7 @@ final class AsyncQueueTests: XCTestCase {
let expB = expectation(description: "Task B")

queue.addOperation {
try await Task.sleep(milliseconds: 100)
try await Task.sleep(for: .milliseconds(100))

expA.fulfill()
}
Expand All @@ -95,7 +89,7 @@ final class AsyncQueueTests: XCTestCase {

let expA = expectation(description: "Task A")
queue.addBarrierOperation {
try await Task.sleep(milliseconds: 100)
try await Task.sleep(for: .milliseconds(100))

expA.fulfill()
}
Expand All @@ -116,13 +110,13 @@ final class AsyncQueueTests: XCTestCase {
let expC = expectation(description: "Task C")

queue.addBarrierOperation {
try await Task.sleep(milliseconds: 100)
try await Task.sleep(for: .milliseconds(100))

expA.fulfill()
}

queue.addOperation {
try await Task.sleep(milliseconds: 100)
try await Task.sleep(for: .milliseconds(100))

expB.fulfill()
}
Expand All @@ -143,11 +137,11 @@ final class AsyncQueueTests: XCTestCase {

queue.addBarrierOperation {
queue.addBarrierOperation {
try await Task.sleep(milliseconds: 100)
try await Task.sleep(for: .milliseconds(100))
expB.fulfill()
}

try await Task.sleep(milliseconds: 100)
try await Task.sleep(for: .milliseconds(100))

expA.fulfill()
}
Expand All @@ -168,15 +162,15 @@ final class AsyncQueueTests: XCTestCase {

queue.addBarrierOperation {
queue.addBarrierOperation {
try await Task.sleep(milliseconds: 100)
try await Task.sleep(for: .milliseconds(100))
expB.fulfill()
}

queue.addOperation {
expC.fulfill()
}

try await Task.sleep(milliseconds: 100)
try await Task.sleep(for: .milliseconds(100))

expA.fulfill()
}
Expand All @@ -192,7 +186,7 @@ final class AsyncQueueTests: XCTestCase {

queue.addOperation {
// slow, non-barrier
try await Task.sleep(milliseconds: 100)
try await Task.sleep(for: .milliseconds(100))

expA.fulfill()
}
Expand All @@ -213,7 +207,7 @@ final class AsyncQueueTests: XCTestCase {
let expB = expectation(description: "Task B")

let task = queue.addOperation {
try await Task.sleep(milliseconds: 100)
try await Task.sleep(for: .milliseconds(100))

expA.fulfill()
}
Expand Down Expand Up @@ -252,7 +246,7 @@ extension AsyncQueueTests {
expA.isInverted = true

let task = queue.addOperation {
try await Task.sleep(milliseconds: 100)
try await Task.sleep(for: .milliseconds(100))

expA.fulfill()
}
Expand Down

0 comments on commit b465d96

Please sign in to comment.