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
| /// A task that is cancelled if goes out of scope, i.e. the last reference on it has been discarded. | |
| public final class ScopedTask<Success: Sendable, Failure: Error>: Sendable { | |
| /// The underlying task | |
| let wrapped: Task<Success, Failure> | |
| /// Wraps a task into a scoped task. | |
| init(wrapping task: Task<Success, Failure>) { | |
| wrapped = task | |
| } | |
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
| import Synchronization | |
| func untilCancelled() async { | |
| print("1") | |
| let mutex: Mutex<CheckedContinuation<Void, Never>?> = .init(nil) | |
| await withTaskCancellationHandler { | |
| print("2") | |
| await withCheckedContinuation { continuation in | |
| print("3") |
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
| import Foundation | |
| import Synchronization | |
| class Thing { | |
| var value: Int = 0 | |
| var observers: [UUID: AsyncStream<Int>.Continuation] = [:] | |
| func nextValue() async throws -> Int { | |
| let id = UUID() | |
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
| import Foundation | |
| import Synchronization | |
| /// Synchronization mechanism to support cooperative and cancellable waiting on a value that _might_ become available _at some point in the future_. | |
| public final class UncertainFuture<Value: Sendable>: Sendable { | |
| /// Initializes a new uncertain future. | |
| public init() {} | |
| /// Return the passed value to all currently suspended callers waiting for ``value``. | |
| public func complete(_ value: Value) { |
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
| import SwiftUI | |
| @main | |
| struct focustestApp: App { | |
| @FocusedValue(\.color) var focusedColor: String? | |
| var body: some Scene { | |
| WindowGroup { | |
| ContentView() | |
| } |
OlderNewer