AutoCat/AutoCatCore/Utils/AutoCancellable.swift
2025-03-16 22:23:03 +03:00

27 lines
543 B
Swift

//
// AutoCancellable.swift
// AutoCat
//
// Created by Selim Mustafaev on 18.02.2025.
// Copyright © 2025 Selim Mustafaev. All rights reserved.
//
import Foundation
@propertyWrapper
public struct AutoCancellable<C: Sendable, E: Error> {
public var wrappedValue: Task<C,E>? {
didSet {
if let oldValue, oldValue.isCancelled {
return
}
oldValue?.cancel()
}
}
public init(wrappedValue: Task<C,E>?) {
self.wrappedValue = wrappedValue
}
}