Skip to content

Commit f1ff3cd

Browse files
authored
Create Task API -> 0.7.0 (#51)
1 parent 2985121 commit f1ff3cd

File tree

11 files changed

+928
-689
lines changed

11 files changed

+928
-689
lines changed

AsyncQueue.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'AsyncQueue'
3-
s.version = '0.6.1'
3+
s.version = '0.7.0'
44
s.license = 'MIT'
55
s.summary = 'A queue that enables ordered sending of events from synchronous to asynchronous code.'
66
s.homepage = 'https://github.com/dfed/swift-async-queue'

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ func testFIFOQueueOrdering() async {
5151
actor Counter {
5252
nonisolated
5353
func incrementAndAssertCountEquals(_ expectedCount: Int) {
54-
queue.enqueue {
54+
Task(on: queue) {
5555
await self.increment()
5656
let incrementedCount = await self.count
5757
XCTAssertEqual(incrementedCount, expectedCount) // always succeeds
5858
}
5959
}
6060

6161
func flushQueue() async {
62-
await queue.enqueueAndWait { }
62+
await Task(on: queue) {}.value
6363
}
6464

6565
func increment() {
@@ -101,14 +101,14 @@ func testActorQueueOrdering() async {
101101

102102
nonisolated
103103
func incrementAndAssertCountEquals(_ expectedCount: Int) {
104-
queue.enqueue { myself in
104+
await Task(on: queue) { myself in
105105
myself.count += 1
106106
XCTAssertEqual(expectedCount, myself.count) // always succeeds
107107
}
108108
}
109109

110110
func flushQueue() async {
111-
await queue.enqueueAndWait { _ in }
111+
await Task(on: queue) {}.value
112112
}
113113

114114
private var count = 0
@@ -127,25 +127,25 @@ func testActorQueueOrdering() async {
127127

128128
### Sending ordered asynchronous tasks to the `@MainActor` from a nonisolated context
129129

130-
Use a `MainActorQueue` to send ordered asynchronous tasks to the `@MainActor`’s isolated context from nonisolated or synchronous contexts. Tasks sent to this queue type are guaranteed to begin executing in the order in which they are enqueued. Like an `ActorQueue`, execution order is guaranteed only until the first [suspension point](https://docs.swift.org/swift-book/LanguageGuide/Concurrency.html#ID639) within the enqueued task. A `MainActorQueue` executes tasks within its adopted actor’s isolated context, resulting in `MainActorQueue` task execution having the same properties as a `@MainActor`'s' code execution: code between suspension points is executed atomically, and tasks sent to a single `MainActorQueue` can await results from the queue without deadlocking.
130+
Use `MainActor.queue` to send ordered asynchronous tasks to the `@MainActor`’s isolated context from nonisolated or synchronous contexts. Tasks sent to this queue type are guaranteed to begin executing in the order in which they are enqueued. Like an `ActorQueue`, execution order is guaranteed only until the first [suspension point](https://docs.swift.org/swift-book/LanguageGuide/Concurrency.html#ID639) within the enqueued task. A `MainActor.queue` executes tasks within its adopted actor’s isolated context, resulting in `MainActor.queue` task execution having the same properties as a `@MainActor`'s' code execution: code between suspension points is executed atomically, and tasks sent to a single `MainActor.queue` can await results from the queue without deadlocking.
131131

132-
A `MainActorQueue` can easily execute asynchronous tasks from a nonisolated context in FIFO order:
132+
A `MainActor.queue` can easily execute asynchronous tasks from a nonisolated context in FIFO order:
133133
```swift
134134
@MainActor
135135
func testMainActorQueueOrdering() async {
136136
@MainActor
137137
final class Counter {
138138
nonisolated
139139
func incrementAndAssertCountEquals(_ expectedCount: Int) {
140-
MainActorQueue.shared.enqueue {
140+
Task(on: MainActor.queue) {
141141
self.increment()
142142
let incrementedCount = self.count
143143
XCTAssertEqual(incrementedCount, expectedCount) // always succeeds
144144
}
145145
}
146146

147147
func flushQueue() async {
148-
await MainActorQueue.shared.enqueueAndWait { }
148+
await Task(on: MainActor.queue) { }.value
149149
}
150150

151151
func increment() {
@@ -181,7 +181,7 @@ To install swift-async-queue in your project with [Swift Package Manager](https:
181181

182182
```swift
183183
dependencies: [
184-
.package(url: "https://github.com/dfed/swift-async-queue", from: "0.6.0"),
184+
.package(url: "https://github.com/dfed/swift-async-queue", from: "0.7.0"),
185185
]
186186
```
187187

@@ -190,7 +190,7 @@ dependencies: [
190190
To install swift-async-queue in your project with [CocoaPods](http://cocoapods.org), add the following to your `Podfile`:
191191

192192
```
193-
pod 'AsyncQueue', '~> 0.6.0'
193+
pod 'AsyncQueue', '~> 0.7.0'
194194
```
195195

196196
## Contributing

0 commit comments

Comments
 (0)