diff --git a/Sources/ElixxirDAppsSDK/Cancellable.swift b/Sources/ElixxirDAppsSDK/Cancellable.swift index 1984e3f10916319e9e88959aa7f21f554d0d0e27..f6897f8d9bdb584053947ab08878643d9eab7028 100644 --- a/Sources/ElixxirDAppsSDK/Cancellable.swift +++ b/Sources/ElixxirDAppsSDK/Cancellable.swift @@ -1,11 +1,18 @@ public final class Cancellable { public init(cancel: @escaping () -> Void) { - self.cancel = cancel + self.onCancel = cancel } deinit { cancel() } - public let cancel: () -> Void + public func cancel() { + guard isCancelled == false else { return } + isCancelled = true + onCancel() + } + + private var isCancelled = false + private let onCancel: () -> Void }