Skip to content

Commit

Permalink
Fixes for swift 6
Browse files Browse the repository at this point in the history
  • Loading branch information
gh123man committed Oct 16, 2024
1 parent 6ea9612 commit a071339
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Benchmarks/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.9
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription

Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.7
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand Down
4 changes: 2 additions & 2 deletions Sources/AsyncChannels/Select.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ protocol SelectProtocol {
}

@usableFromInline
struct ReceiveHandler<T>: SelectProtocol {
struct ReceiveHandler<T: Sendable>: SelectProtocol {

private var chan: Channel<T>
private let outFunc: (T?) async -> ()
Expand Down Expand Up @@ -59,7 +59,7 @@ struct NoneHandler: SelectProtocol {
}

@usableFromInline
struct SendHandler<T>: SelectProtocol {
struct SendHandler<T: Sendable>: SelectProtocol {
private var chan: Channel<T>
private let val: T
private let onSend: () async -> ()
Expand Down
41 changes: 39 additions & 2 deletions Tests/AsyncChannelsTests/AsyncChannelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ final class AsyncTest: XCTestCase {

func failAfter(duration: Duration) -> Channel<Bool> {
let stop = Channel<Bool>()
let sleepSig = sleep(for: .seconds(1))
Task {
await select {
receive(stop)
receive(sleep(for: duration)) {
receive(sleepSig) {
XCTFail("Test timed out")
exit(1)
}
Expand Down Expand Up @@ -615,7 +616,7 @@ final class AsyncTest: XCTestCase {
a.close()
}

class SomeData {
final class SomeData: Sendable {
let name: String
let age: Int

Expand Down Expand Up @@ -769,4 +770,40 @@ final class AsyncTest: XCTestCase {

XCTAssertEqual(100, sum)
}

func testStopSig() async {

enum StopSignal {
case error
case done
}

let data = Channel<String>()
let signal = Channel<StopSignal>()


Task {
var done = false
while !done {
await select {
receive(data) { print($0!) }
receive(signal) {
switch $0! {
case .error:
print("there was an error")
done = true
case .done:
print("done processing data")
done = true
}
}
}
}
print("done!")
}

await data <- "foo"
await data <- "bar"
await signal <- .done
}
}

0 comments on commit a071339

Please sign in to comment.