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
// | |
// AppModuleEnvironmentConfiguration.swift | |
// | |
import SwiftUI | |
// MARK: AppDelegate | |
final class AppDelegate: NSObject, UIApplicationDelegate { | |
func application( |
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
// | |
// RestrictiveResourceLoader.swift | |
// | |
import Foundation | |
/// Simple example on how to restrict access to one or more "resources" (local storage, remote endpoint, etc). | |
/// Very similar to how one would use a semaphore for protected access. | |
final actor RestrictiveResourceLoader { | |
private var isFetchingResource: Bool = false |
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
// | |
// AsyncSemaphore.swift | |
// | |
import Foundation | |
/// An AsyncSemaphore suited for use in asynchronous contexts. Heavily inspired by https://github.com/groue/Semaphore. | |
public final class AsyncSemaphore: @unchecked Sendable { | |
final class QueuedContinuation: @unchecked Sendable { | |
enum State { |
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
// | |
// ContinuationCreatingTaskSpawningCancelingResourceCache.swift | |
// | |
import Foundation | |
/// A concurrent and thread safe resource cache that spawns an unstructured Task to fetch a resource when the resource is first requested. | |
/// All Tasks requesting the resource will be suspended, and a Continuation will be created and stored for each Task. | |
/// Continuations and Tasks will then be resumed once the unstructured resource fetching Task has finished fetching the resource. | |
/// If a resource requesting Task is canceled while suspended and waiting for the unstructured resource fetching Task, |
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
import Foundation | |
import Atomics | |
/// A thread/concurrency context safe value using [Swift Atomics](https://github.com/apple/swift-atomics). | |
private final class AtomicCount: Sendable { | |
private let protectedValue = ManagedAtomic<Int>(0) | |
var value: Int { | |
protectedValue.load(ordering: .acquiring) | |
} |
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
// | |
// TaskSpawningCancelingResourceCache.swift | |
// | |
import Foundation | |
import Atomics | |
/// A thread/concurrency context safe value using [Swift Atomics](https://github.com/apple/swift-atomics). | |
/// Heavily inspired by this WWDC 2023 video: [Beyond the basics of structured concurrency](https://developer.apple.com/videos/play/wwdc2023/10170/). | |
final class AtomicCount: Sendable { |
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
// | |
// TaskSpawningResourceCache.swift | |
// | |
import Foundation | |
/// A concurrent and thread safe resource cache that spawns an unstructured Task to fetch a resource when the resource is first requested. | |
/// All Tasks requesting the resource will wait on the completion of the spawned unstructured resource fetching Task. | |
final actor TaskSpawningResourceCache { | |
private let urlSession: URLSession |
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
// | |
// ContinuationCreatingCancelingResourceCache.swift | |
// | |
import Foundation | |
/// A thread/concurrency context safe storage for Continuations using [NSLock](https://developer.apple.com/documentation/foundation/nslock). | |
/// Heavily inspired by this WWDC 2023 video: [Beyond the basics of structured concurrency](https://developer.apple.com/videos/play/wwdc2023/10170/). | |
/// | |
/// NOTE: Be careful to always resume any suspended Continuations to prevent Continuation / Task leaks. |
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
// | |
// ContinuationCreatingResourceCache.swift | |
// | |
import Foundation | |
/// A thread/concurrency context safe storage for Continuations using [NSLock](https://developer.apple.com/documentation/foundation/nslock). | |
/// Heavily inspired by this WWDC 2023 video: [Beyond the basics of structured concurrency](https://developer.apple.com/videos/play/wwdc2023/10170/). | |
/// | |
/// NOTE: Be careful to always resume any suspended Continuations to prevent Continuation / Task leaks. |
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
// | |
// StopRunLoopSource.swift | |
// | |
import Foundation | |
final class StopRunLoopSource: NSObject { | |
// More on how to define custom run loop input sources: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Multithreading/RunLoopManagement/RunLoopManagement.html#//apple_ref/doc/uid/10000057i-CH16-SW3 | |
// And tips on how to terminate threads: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Multithreading/CreatingThreads/CreatingThreads.html#//apple_ref/doc/uid/10000057i-CH15-SW10 |
NewerOlder