Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,21 @@ jobs:
id: destination
run: |
case "${{ matrix.platform }}" in
ios)
destination="platform=iOS Simulator,name=iPhone 16 Pro Max,OS=latest"
;;
maccatalyst)
destination="platform=macOS,variant=Mac Catalyst"
;;
ios)
destination="platform=iOS Simulator,name=iPhone 16 Pro Max,OS=latest"
;;
tvos)
destination="platform=tvOS Simulator,name=Apple TV 4K (3rd generation),OS=latest"
;;
visionos)
destination="platform=visionOS Simulator,name=Apple Vision Pro,OS=latest"
;;
watchos)
destination="platform=watchOS Simulator,name=Apple Watch Series 10 (46mm),OS=latest"
;;
visionos)
destination="platform=visionOS Simulator,name=Apple Vision Pro,OS=latest"
;;
*)
echo "Unknown platform: ${{ matrix.platform }}"
exit 1
Expand Down
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.0
6.1
4 changes: 2 additions & 2 deletions Sources/PrincipleConcurrency/DeadlineExceededError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public func withDeadline<C: Clock, Success: Sendable>(
clock: C,
priority: TaskPriority? = nil,
isolation: isolated (any Actor)? = #isolation,
@_inheritActorContext @_implicitSelfCapture operation: sending @escaping @isolated(any) () async throws -> Success
@_inheritActorContext @_implicitSelfCapture operation: sending @escaping () async throws -> Success
) async throws -> Success {
try await withTimeLimit(
throwing: DeadlineExceededError(),
Expand Down Expand Up @@ -65,7 +65,7 @@ public func withDeadline<Success: Sendable>(
tolerance: Duration? = nil,
priority: TaskPriority? = nil,
isolation: isolated (any Actor)? = #isolation,
@_inheritActorContext @_implicitSelfCapture operation: sending @escaping @isolated(any) () async throws -> Success
@_inheritActorContext @_implicitSelfCapture operation: sending @escaping () async throws -> Success
) async throws -> Success {
try await withDeadline(
until: deadline,
Expand Down
12 changes: 7 additions & 5 deletions Sources/PrincipleConcurrency/TaskTimeLimit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
// Copyright © 2024 Philipp Gabriel. Original code licensed under MIT.
//

private enum TaskTimeLimit {
private enum TaskTimeLimit<Success: Sendable> {

enum Event<Success: Sendable> {
enum Event {

case taskFinished(Result<Success, any Error>)
case parentTaskCancelled
Expand All @@ -26,20 +26,22 @@ internal func withTimeLimit<C: Clock, Success: Sendable>( // swiftlint:disable:t
clock: C,
priority: TaskPriority?,
isolation: isolated (any Actor)?,
operation: sending @escaping @isolated(any) () async throws -> Success
operation: sending @escaping () async throws -> Success
) async throws -> Success {
var transfer = SingleUseTransfer(operation)

let result = await withTaskGroup(
of: TaskTimeLimit.Event<Success>.self,
of: TaskTimeLimit<Success>.Event.self,
returning: Result<Success, any Error>.self,
isolation: isolation,
body: { group in
var transfer = transfer.take()

group.addTask(priority: priority) {
do {
// Review after closure isolation control gets implemented
// https://github.com/swiftlang/swift-evolution/blob/main/proposals/0461-async-function-isolation.md
// https://github.com/swiftlang/swift-evolution/blob/main/proposals/0472-task-start-synchronously-on-caller-context.md
// https://forums.swift.org/t/explicitly-captured-isolated-parameter-does-not-change-isolation-of-sendable-sending-closures/79502
// https://forums.swift.org/t/closure-isolation-control/70378
let success = try await transfer.finalize()()
return .taskFinished(.success(success))
Expand Down
4 changes: 2 additions & 2 deletions Sources/PrincipleConcurrency/TimeoutError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public func withTimeout<C: Clock, Success: Sendable>(
clock: C,
priority: TaskPriority? = nil,
isolation: isolated (any Actor)? = #isolation,
@_inheritActorContext @_implicitSelfCapture operation: sending @escaping @isolated(any) () async throws -> Success
@_inheritActorContext @_implicitSelfCapture operation: sending @escaping () async throws -> Success
) async throws -> Success {
try await withTimeLimit(
throwing: TimeoutError(),
Expand Down Expand Up @@ -65,7 +65,7 @@ public func withTimeout<Success: Sendable>(
tolerance: Duration? = nil,
priority: TaskPriority? = nil,
isolation: isolated (any Actor)? = #isolation,
@_inheritActorContext @_implicitSelfCapture operation: sending @escaping @isolated(any) () async throws -> Success
@_inheritActorContext @_implicitSelfCapture operation: sending @escaping () async throws -> Success
) async throws -> Success {
try await withTimeout(
duration,
Expand Down
13 changes: 13 additions & 0 deletions Tests/PrincipleConcurrencyTests/CustomActor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// CustomActor.swift
// Principle
//
// Created by Kamil Strzelecki on 24/04/2025.
// Copyright © 2025 Kamil Strzelecki. All rights reserved.
//

@globalActor
internal actor CustomActor {

static let shared = CustomActor()
}
20 changes: 20 additions & 0 deletions Tests/PrincipleConcurrencyTests/TaskTimeLimitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ internal struct TaskTimeLimitTests {
try await task.value
}
}

@Test
func testIsolation() async throws {
let task = Task { @CustomActor in
try await withDeadline(until: .now + .seconds(1)) {
CustomActor.shared.assertIsolated()
}
}
try await task.value
}
}

struct Timeout {
Expand Down Expand Up @@ -99,6 +109,16 @@ internal struct TaskTimeLimitTests {
try await task.value
}
}

@Test
func testIsolation() async throws {
let task = Task { @CustomActor in
try await withTimeout(.seconds(1)) {
CustomActor.shared.assertIsolated()
}
}
try await task.value
}
}
}

Expand Down