Created
April 9, 2025 06:38
-
-
Save jacobsapps/62311df851f5772c990862c9d537fd47 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
actor TaskActor { | |
private var cachedTask: Task<Void, Error>? | |
func run(_ operation: @escaping @Sendable () async throws -> Void) async throws { | |
if cachedTask == nil { | |
cachedTask = Task { | |
try await operation() | |
} | |
} | |
defer { cachedTask = nil } | |
try await cachedTask!.value | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment