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
// | |
// PendingOperation.swift | |
// | |
import Foundation | |
/// A utility type for letting multiple caller Tasks wait for a future value produced by an asynchronous operation. | |
public final class PendingOperation<T: Sendable>: @unchecked Sendable { | |
private let lock = NSLock() |
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
// | |
// MockURLProtocol.swift | |
// | |
/// Inspired by [Testing Tips & Tricks](https://developer.apple.com/videos/play/wwdc2018/417). | |
final class MockURLProtocol: URLProtocol { | |
static nonisolated(unsafe) var responseBuilders: [(URLRequest) throws -> (Data, HTTPURLResponse, URLRequest?)] = [] | |
override static func canInit(with request: URLRequest) -> Bool { | |
!responseBuilders.isEmpty |
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
// | |
// AsyncValues.swift | |
// | |
/// An `AsyncSequence` that accept a closure to produce its values at an optional `TimeInterval`. | |
/// | |
/// The `Context` can be used to track relevant information between each iteration of the `AsyncSequence`. | |
public struct AsyncValues<Value: Sendable, Context: Sendable>: AsyncSequence { | |
public struct Iterator: AsyncIteratorProtocol { | |
private let interval: TimeInterval |
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
// | |
// PendingValue.swift | |
// | |
import Foundation | |
/// A utility type for letting multiple caller Tasks wait for a future value, whom exact arrival is unknown and will be manually triggered some time in the future. | |
public final class PendingValue<T: Sendable>: @unchecked Sendable { | |
private let lock = NSLock() |
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
// | |
// HTTPAPIProblem.swift | |
// | |
import Foundation | |
// MARK: HTTP API Problem | |
/// Error thrown when decoding a`HTTPAPIProblem` if the decoded HTTP API Problem's type does not match the type of the associated `Extras`. | |
public struct HTTPAPIProblemTypeMismatch: Error {} |
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
// | |
// AppModuleEnvironmentConfiguration.swift | |
// | |
import SwiftUI | |
// MARK: AppDelegate | |
final class AppDelegate: NSObject, UIApplicationDelegate { | |
func application( |
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
// | |
// 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 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
// | |
// 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 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
// | |
// 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 |
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
// | |
// RunLoopObserving.swift | |
// | |
import Foundation | |
func name(for thread: Thread) -> String { | |
if let name = Thread.current.name, !name.isEmpty { | |
return name | |
} else { |
NewerOlder