diff --git a/Runtime/Scripts/Helpers/CoroutineRunner.cs b/Runtime/Scripts/Helpers/CoroutineRunner.cs
new file mode 100644
index 00000000..93cfc967
--- /dev/null
+++ b/Runtime/Scripts/Helpers/CoroutineRunner.cs
@@ -0,0 +1,27 @@
+using System;
+using System.Collections;
+using UnityEngine;
+
+///
+/// Helper class that will allow to run a coroutine
+///
+public class CoroutineRunner : MonoBehaviour
+{
+ private static CoroutineRunner _instance;
+
+ public static CoroutineRunner Instance
+ {
+ get
+ {
+ if (_instance == null)
+ _instance = (new GameObject("CoroutineRunner")).AddComponent();
+
+ return _instance;
+ }
+ }
+
+ private void Awake()
+ {
+ DontDestroyOnLoad(gameObject);
+ }
+}
diff --git a/Runtime/Scripts/Helpers/CoroutineWrapper.cs.meta b/Runtime/Scripts/Helpers/CoroutineRunner.cs.meta
similarity index 83%
rename from Runtime/Scripts/Helpers/CoroutineWrapper.cs.meta
rename to Runtime/Scripts/Helpers/CoroutineRunner.cs.meta
index e602a490..8fa57ae7 100644
--- a/Runtime/Scripts/Helpers/CoroutineWrapper.cs.meta
+++ b/Runtime/Scripts/Helpers/CoroutineRunner.cs.meta
@@ -1,5 +1,5 @@
fileFormatVersion: 2
-guid: 39830bc66b1aa4e8ca77da851c0a25ff
+guid: dd493b835c5e842799b48829edd361be
MonoImporter:
externalObjects: {}
serializedVersion: 2
diff --git a/Runtime/Scripts/Helpers/CoroutineUtils.cs b/Runtime/Scripts/Helpers/CoroutineUtils.cs
index dc60ab8c..4ad36a89 100644
--- a/Runtime/Scripts/Helpers/CoroutineUtils.cs
+++ b/Runtime/Scripts/Helpers/CoroutineUtils.cs
@@ -41,6 +41,5 @@ public static IEnumerator Try(
}
yield return current;
}
- exceptionHandler?.Invoke(null);
}
-}
\ No newline at end of file
+}
diff --git a/Runtime/Scripts/Helpers/CoroutineWrapper.cs b/Runtime/Scripts/Helpers/CoroutineWrapper.cs
deleted file mode 100644
index 5a053885..00000000
--- a/Runtime/Scripts/Helpers/CoroutineWrapper.cs
+++ /dev/null
@@ -1,99 +0,0 @@
-using System;
-using System.Collections;
-using UnityEngine;
-
-///
-/// Wraps a coroutine allowing to extract the result when it's completed
-///
-/// Type of result expected
-public class CoroutineWrapper : IEnumerator
-{
- ///
- /// Event raised when the coroutine is complete
- ///
- public readonly Action Completed;
-
- private readonly IEnumerator _targetCoroutine;
-
- ///
- /// Exception triggered during the execution of the coroutine.
- ///
- public Exception Exception { get; private set; }
-
- ///
- public object Current { get; private set; }
-
- ///
- /// Result extracted from the coroutine when it's complete
- ///
- public T Result { get; private set; }
-
- ///
- /// Create an instance of the wrapper
- ///
- /// Coroutine that will be executed
- /// Callback that will be called when the coroutine is complete
- public CoroutineWrapper(IEnumerator coroutine, Action callback = null)
- {
- _targetCoroutine = coroutine;
- if (callback != null)
- {
- Completed += callback;
- }
- }
-
- ///
- public bool MoveNext()
- {
- try
- {
- if (_targetCoroutine.MoveNext())
- {
- Current = _targetCoroutine.Current;
- return true;
- }
-
- Result = (T)_targetCoroutine.Current;
- Current = _targetCoroutine.Current;
- Completed?.Invoke(Result);
- return false;
- }
- catch (Exception e)
- {
- Debug.LogError("Exception " + e.Message);
- Exception = e;
- Completed?.Invoke(default);
- return false;
- }
- }
-
- ///
- public void Reset()
- {
- _targetCoroutine.Reset();
- }
-}
-
-///
-/// Helper class that will allow to run a coroutine
-///
-public class CoroutineRunner : MonoBehaviour
-{
- private static CoroutineRunner _instance;
-
- public static CoroutineRunner Instance
- {
- get
- {
- if (_instance == null)
- _instance = (new GameObject("CoroutineRunner")).AddComponent();
-
- return _instance;
- }
- }
-
- private void Awake()
- {
- DontDestroyOnLoad(gameObject);
- }
-}
\ No newline at end of file
diff --git a/Runtime/Scripts/TezosAPI/HttpClient.cs b/Runtime/Scripts/TezosAPI/HttpClient.cs
index d9262261..d20543f2 100644
--- a/Runtime/Scripts/TezosAPI/HttpClient.cs
+++ b/Runtime/Scripts/TezosAPI/HttpClient.cs
@@ -64,10 +64,9 @@ private UnityWebRequest GetUnityWebRequest(string method, string path)
public static IEnumerator WrappedRequest(IEnumerator op, Action callback)
{
- var counterRoutine = new CoroutineWrapper(op);
+ var counterRoutine = CoroutineUtils.Try(op);
yield return counterRoutine;
- var counter = counterRoutine.Result;
- callback?.Invoke(counter);
+ callback?.Invoke((T) counterRoutine.Current);
}
}
@@ -77,4 +76,4 @@ internal static class HttpHeaders
public static KeyValuePair Accept => new("Accept", "application/json");
public static KeyValuePair UserAgent => new("User-Agent", "tezos-unity-sdk");
}
-}
\ No newline at end of file
+}