-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from markbattistella/2024.08.03
2024-08-03 - Updated to Swift 6 concurrency
- Loading branch information
Showing
8 changed files
with
59 additions
and
11 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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// Project: | ||
// Author: Mark Battistella | ||
// Website: https://markbattistella.com | ||
// | ||
|
||
import Foundation | ||
|
||
/// A global actor to manage concurrency for shared resources. | ||
/// | ||
/// The `GlobalActor` is used to ensure that certain shared resources are accessed | ||
/// in a thread-safe manner. By isolating code to this actor, we prevent data races | ||
/// and ensure safe access to globally accessible variables. | ||
/// | ||
/// Usage: | ||
/// ```swift | ||
/// @ZodiacActor | ||
/// public var sharedResource: SomeType = ... | ||
/// | ||
/// @ZodiacActor | ||
/// public func performThreadSafeOperation() { | ||
/// // Code that interacts with sharedResource | ||
/// } | ||
/// ``` | ||
/// | ||
/// You can also use `await` to call functions isolated to this actor: | ||
/// ```swift | ||
/// await GlobalActor.run { | ||
/// performThreadSafeOperation() | ||
/// } | ||
/// ``` | ||
/// | ||
/// - Note: Make sure to use the `@ZodiacActor` attribute to isolate global variables or functions. | ||
@globalActor | ||
public actor ZodiacActor { | ||
|
||
/// The shared instance of the global actor. | ||
public static let shared = ZodiacActor() | ||
} |
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