Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deprecated message cannot handle in swift 5 #51

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 1 addition & 3 deletions Sources/ServiceContextModule/ServiceContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,12 @@ extension ServiceContext {
}

@available(*, deprecated, message: "Use the method with the isolation parameter instead.")
// Deprecated trick to avoid executor hop here; 6.0 introduces the proper replacement: #isolation
@_disfavoredOverload
public static func withValue<T>(_ value: ServiceContext?, operation: () async throws -> T) async rethrows -> T {
try await ServiceContext.$current.withValue(value, operation: operation)
}
#else
// Deprecated trick to avoid executor hop here; 6.0 introduces the proper replacement: #isolation
@available(*, deprecated, message: "Prefer withValue(_:isolation:operation:)")
@_disfavoredOverload
@_unsafeInheritExecutor
public static func withValue<T>(_ value: ServiceContext?, operation: () async throws -> T) async rethrows -> T {
try await ServiceContext.$current.withValue(value, operation: operation)
Expand Down
3 changes: 3 additions & 0 deletions Tests/ServiceContextTests/ServiceContextTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ final class ServiceContextTests: XCTestCase {
ServiceContext.withValue(.topLevel) {
value = 12 // should produce no warnings
}
await ServiceContext.withValue(.topLevel) { () async in
value = 12 // should produce no warnings
}
}
}

Expand Down