-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix up some concurrency warnings, deprecate runUnsafely
- Loading branch information
1 parent
e4bab59
commit 39504ac
Showing
8 changed files
with
35 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,12 @@ | ||
import Foundation | ||
|
||
public extension MainActor { | ||
extension MainActor { | ||
/// Execute the given body closure on the main actor without enforcing MainActor isolation. | ||
/// | ||
/// It will crash if run on any non-main thread. | ||
@available(*, deprecated, message: "Please move to assumeIsolated") | ||
@_unavailableFromAsync | ||
static func runUnsafely<T>(_ body: @MainActor () throws -> T) rethrows -> T { | ||
#if swift(>=5.9) | ||
if #available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) { | ||
return try MainActor.assumeIsolated(body) | ||
} | ||
#endif | ||
|
||
dispatchPrecondition(condition: .onQueue(.main)) | ||
return try withoutActuallyEscaping(body) { fn in | ||
try unsafeBitCast(fn, to: (() throws -> T).self)() | ||
} | ||
public static func runUnsafely<T>(_ body: @MainActor () throws -> T) rethrows -> T where T : Sendable{ | ||
try MainActor.assumeIsolated(body) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters