-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removing priority set concept, new tests for bug fixes
- Loading branch information
1 parent
32ef005
commit d7837cd
Showing
19 changed files
with
340 additions
and
244 deletions.
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
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
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
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,71 @@ | ||
struct AwaitableQueue<Element> { | ||
private typealias Continuation = CheckedContinuation<Void, Never> | ||
|
||
private enum Event { | ||
case element(Element) | ||
case waiter(Continuation) | ||
} | ||
|
||
private var pendingEvents = [Event]() | ||
|
||
init() { | ||
|
||
} | ||
|
||
public var hasPendingEvents: Bool { | ||
pendingEvents.contains { event in | ||
switch event { | ||
case .element: | ||
true | ||
case .waiter: | ||
false | ||
} | ||
} | ||
} | ||
|
||
public mutating func processingCompleted(isolation: isolated any Actor) async { | ||
if hasPendingEvents == false { | ||
return | ||
} | ||
|
||
await withCheckedContinuation { continuation in | ||
self.pendingEvents.append(.waiter(continuation)) | ||
} | ||
} | ||
|
||
public mutating func enqueue(_ element: Element) { | ||
self.pendingEvents.append(.element(element)) | ||
} | ||
|
||
public var pendingElements: [Element] { | ||
pendingEvents.compactMap { | ||
switch $0 { | ||
case let .element(value): | ||
value | ||
case .waiter: | ||
nil | ||
} | ||
} | ||
} | ||
|
||
public mutating func handlePendingWaiters() { | ||
while let event = pendingEvents.first { | ||
guard case let .waiter(continuation) = event else { break } | ||
|
||
continuation.resume() | ||
pendingEvents.removeFirst() | ||
} | ||
} | ||
|
||
mutating func next() -> Element? { | ||
handlePendingWaiters() | ||
|
||
guard case let .element(first) = pendingEvents.first else { | ||
return nil | ||
} | ||
|
||
self.pendingEvents.removeFirst() | ||
|
||
return first | ||
} | ||
} |
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
Oops, something went wrong.