Implement session cache upgrade phase 1 foundation
This commit is contained in:
14
MLXServer/Server/CancellationToken.swift
Normal file
14
MLXServer/Server/CancellationToken.swift
Normal file
@@ -0,0 +1,14 @@
|
||||
import os
|
||||
|
||||
/// Thread-safe cancellation flag for cooperative stream shutdown.
|
||||
final class CancellationToken: @unchecked Sendable {
|
||||
private let lock = OSAllocatedUnfairLock(initialState: false)
|
||||
|
||||
var isCancelled: Bool {
|
||||
lock.withLock { $0 }
|
||||
}
|
||||
|
||||
func cancel() {
|
||||
lock.withLock { $0 = true }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user