Skip to content

Commit

Permalink
Update unit tests and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
gh123man committed Jul 8, 2024
1 parent 3b8bbdf commit c98d165
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ await msg <- "bar"
print(await <-msg) // foo
print(await <-msg) // bar

// The channel is now empty.
// The msg channel is now empty.
```

### Closing Channels
Expand Down Expand Up @@ -134,7 +134,7 @@ The loop will break when the channel is closed.

`none { ... }` if none of the channel operations were ready, none will execute instead.

`any(x1, x2, ...) { x in ... }` or `any(seq) { el in ... }` operates on a sequence and is useful for working with an array of channels.
`any(x1, x2, ...) { x in ... }` or `any(seq) { el in ... }` operates on a sequence and is useful for performing the same operations on multiple channels.

### Examples

Expand All @@ -159,7 +159,7 @@ await select {
let a = Channel<String>(capacity: 10)
let b = Channel<String>(capacity: 10)

// Fill up a
// Fill up channel a
for _ in (0..<10) {
await a <- "a"
}
Expand All @@ -184,13 +184,10 @@ See the [Examples](/Examples/) folder for real world usage.

- [Parallel image converter](/Examples/ImageConverter/Sources/ImageConverter/main.swift) - Saturate the CPU to convert images applying back pressure to the input.

## Notes

If you are looking for a blocking variant of this library for traditional swift concurrency, check out my previous project [Swigo](https://github.com/gh123man/Swigo) which this library is based off of.


# Special Thanks

I could not have gotten this far on my own without the help from the folks over at [forums.swift.org](https://forums.swift.org/t/async-channels-for-swift-concurrency/70752). Big shout-out and thank you to:
I could not have gotten this far without the help from the folks over at [forums.swift.org](https://forums.swift.org/t/async-channels-for-swift-concurrency/70752) and contributors on github. Big shout-out and thank you to:
- [wadetregaskis](https://forums.swift.org/u/wadetregaskis/summary) for optimizing much of this code and finding the more challenging performance limitations (compiler limitations, locking strategies)
- [vns](https://forums.swift.org/u/vns/summary) for proposing a `LinkedList` backing data structure
- [Kuniwak](https://github.com/Kuniwak) for proposing and adding the select `any` function.
17 changes: 9 additions & 8 deletions Tests/AsyncChannelsTests/AsyncChannelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,9 @@ final class AsyncTest: XCTestCase {

for _ in (0..<6) {
await select {
receive(d) { await result <- $0! }
receive(c) { await result <- $0! }
any(d, c) {
receive($0) { await result <- $0! }
}
}
}
result.close()
Expand Down Expand Up @@ -371,8 +372,9 @@ final class AsyncTest: XCTestCase {
var done = false
while !done {
await select {
receive(a) { await c <- $0! }
receive(b) { await c <- $0! }
any(a, b) {
receive($0) { await c <- $0! }
}
receive(done1) { done = true }
}
}
Expand Down Expand Up @@ -412,10 +414,9 @@ final class AsyncTest: XCTestCase {
var done = false
while !done {
await select {
receive(a) { count += 1 }
receive(b) { count += 1 }
receive(c) { count += 1 }
receive(d) { count += 1 }
any(a, b, c, d) {
receive($0) { count += 1 }
}
none {
done = true
}
Expand Down

0 comments on commit c98d165

Please sign in to comment.