Skip to content

Commit

Permalink
Merge pull request #12 from groue/dev/Swift-5.10
Browse files Browse the repository at this point in the history
Bump minimum Swift version to 5.10
  • Loading branch information
groue authored Jul 28, 2024
2 parents ad48ff5 + b12e9c2 commit 2543679
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ jobs:
strategy:
matrix:
os: [macos-latest, ubuntu-latest]
swift-version: ["5.7.0"]
swift-version: ["5.10.0"]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Install Swift ${{ matrix.swift-version }}
if: ${{ runner.os != 'Windows' }}
uses: swift-actions/setup-swift@v1
uses: swift-actions/setup-swift@v2
with:
swift-version: ${{ matrix.swift-version }}
- name: Test
Expand Down
16 changes: 11 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.7
// swift-tools-version: 5.10
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand All @@ -25,12 +25,18 @@ let package = Package(
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "Semaphore",
swiftSettings: [
// .unsafeFlags(["-Xfrontend", "-warn-concurrency", "-strict-concurrency=complete"]),
]),
name: "Semaphore"),
.testTarget(
name: "SemaphoreTests",
dependencies: ["Semaphore"]),
]
)

for target in package.targets {
var settings = target.swiftSettings ?? []
settings.append(contentsOf: [
// <https://github.com/apple/swift-evolution/blob/main/proposals/0337-support-incremental-migration-to-concurrency-checking.md>
.enableExperimentalFeature("StrictConcurrency"),
])
target.swiftSettings = settings
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

**A Synchronization Primitive for Swift Concurrency**

**Requirements**: iOS 13.0+ / macOS 10.15+ / tvOS 13.0+ / watchOS 6.0+ • Swift 5.7+ / Xcode 14+
**Requirements**: iOS 13.0+ / macOS 10.15+ / tvOS 13.0+ / watchOS 6.0+ • Swift 5.10+ / Xcode 15.3+

📖 **[Documentation](https://swiftpackageindex.com/groue/Semaphore/documentation)**

Expand Down
24 changes: 12 additions & 12 deletions Tests/SemaphoreTests/AsyncSemaphoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ final class AsyncSemaphoreTests: XCTestCase {
}
}

func test_wait_suspends_on_zero_semaphore_until_signal() {
func test_wait_suspends_on_zero_semaphore_until_signal() async {
// Check DispatchSemaphore behavior
do {
// Given a zero semaphore
Expand All @@ -88,11 +88,11 @@ final class AsyncSemaphoreTests: XCTestCase {
}.start()

// Then the thread is initially blocked.
wait(for: [ex1], timeout: 0.5)
await fulfillment(of: [ex1], timeout: 0.5)

// When a signal occurs, then the waiting thread is woken.
sem.signal()
wait(for: [ex2], timeout: 1)
await fulfillment(of: [ex2], timeout: 1)
}

// Test that AsyncSemaphore behaves identically
Expand All @@ -111,11 +111,11 @@ final class AsyncSemaphoreTests: XCTestCase {
}

// Then the task is initially suspended.
wait(for: [ex1], timeout: 0.5)
await fulfillment(of: [ex1], timeout: 0.5)

// When a signal occurs, then the suspended task is resumed.
sem.signal()
wait(for: [ex2], timeout: 0.5)
await fulfillment(of: [ex2], timeout: 0.5)
}
}

Expand All @@ -134,7 +134,7 @@ final class AsyncSemaphoreTests: XCTestCase {
}
try await Task.sleep(nanoseconds: 100_000_000)
task.cancel()
wait(for: [ex], timeout: 1)
await fulfillment(of: [ex], timeout: 1)
}

func test_cancellation_before_suspension_throws_CancellationError() throws {
Expand Down Expand Up @@ -180,14 +180,14 @@ final class AsyncSemaphoreTests: XCTestCase {
}

// Then the task is initially suspended.
wait(for: [ex1], timeout: 0.5)
await fulfillment(of: [ex1], timeout: 0.5)

// When a signal occurs, then the suspended task is resumed.
sem.signal()
wait(for: [ex2], timeout: 0.5)
await fulfillment(of: [ex2], timeout: 0.5)
}

func test_that_cancellation_before_suspension_increments_the_semaphore() throws {
func test_that_cancellation_before_suspension_increments_the_semaphore() async throws {
// Given a task cancelled before it waits on a semaphore,
let sem = AsyncSemaphore(value: 0)
let task = Task {
Expand All @@ -212,11 +212,11 @@ final class AsyncSemaphoreTests: XCTestCase {
}

// Then the task is initially suspended.
wait(for: [ex1], timeout: 0.5)
await fulfillment(of: [ex1], timeout: 0.5)

// When a signal occurs, then the suspended task is resumed.
sem.signal()
wait(for: [ex2], timeout: 0.5)
await fulfillment(of: [ex2], timeout: 0.5)
}

// Inspired by <https://github.com/groue/Semaphore/pull/3>
Expand All @@ -241,7 +241,7 @@ final class AsyncSemaphoreTests: XCTestCase {
}

// Then the second task is not suspended.
wait(for: [ex], timeout: 0.5)
await fulfillment(of: [ex], timeout: 0.5)
}

// Test that semaphore can limit the number of concurrent executions of
Expand Down

0 comments on commit 2543679

Please sign in to comment.