From 5808d986fa347214a55389ad8a14748671f713ac Mon Sep 17 00:00:00 2001
From: Dariusz Rybicki <dariusz@elixxir.io>
Date: Mon, 6 Jun 2022 13:58:07 +0200
Subject: [PATCH] FIx Cancellable

Prevent multiple cancellations
---
 Sources/ElixxirDAppsSDK/Cancellable.swift | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/Sources/ElixxirDAppsSDK/Cancellable.swift b/Sources/ElixxirDAppsSDK/Cancellable.swift
index 1984e3f1..f6897f8d 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
 }
-- 
GitLab