Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Sources/SwiftNetwork/Context/NetworkContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,18 @@ extension NetworkContext {
init(globals: Globals) {
self.globals = globals
}
/// A task for the context's queue to run.
///
/// Tasks are not `Sendable`; the queue serializes them, which is the guarantee `NetworkContext` rests on
/// for its own `@unchecked Sendable` conformance.
private struct QueuedTask: @unchecked Sendable {
let run: () -> Void
}
/// Runs an immediate task. This task must not be run directly on the caller's stack, but otherwise
/// no assumptions are made about how the task is run.
func runImmediate(_ task: @escaping (() -> Void)) {
globals.queue.async(execute: DispatchWorkItem(block: task))
let queued = QueuedTask(run: task)
globals.queue.async { queued.run() }
}
/// Schedules a task to run after a delay, using a reference.
func schedule(_ task: @escaping (() -> Void), after delay: NetworkDuration, reference: TimerReference) {
Expand Down
Loading