Skip to content

Commit

Permalink
Use CoroutineUtils.Try in the WrappedRequest method
Browse files Browse the repository at this point in the history
  • Loading branch information
fraidev committed May 2, 2023
1 parent b54594a commit 1e24310
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 106 deletions.
27 changes: 27 additions & 0 deletions Runtime/Scripts/Helpers/CoroutineRunner.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections;
using UnityEngine;

/// <summary>
/// Helper class that will allow to run a coroutine
/// </summary>
public class CoroutineRunner : MonoBehaviour
{
private static CoroutineRunner _instance;

public static CoroutineRunner Instance
{
get
{
if (_instance == null)
_instance = (new GameObject("CoroutineRunner")).AddComponent<CoroutineRunner>();

return _instance;
}
}

private void Awake()
{
DontDestroyOnLoad(gameObject);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Runtime/Scripts/Helpers/CoroutineUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,5 @@ public static IEnumerator Try(
}
yield return current;
}
exceptionHandler?.Invoke(null);
}
}
}
99 changes: 0 additions & 99 deletions Runtime/Scripts/Helpers/CoroutineWrapper.cs

This file was deleted.

7 changes: 3 additions & 4 deletions Runtime/Scripts/TezosAPI/HttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ private UnityWebRequest GetUnityWebRequest(string method, string path)

public static IEnumerator WrappedRequest<T>(IEnumerator op, Action<T> callback)
{
var counterRoutine = new CoroutineWrapper<T>(op);
var counterRoutine = CoroutineUtils.Try(op);
yield return counterRoutine;
var counter = counterRoutine.Result;
callback?.Invoke(counter);
callback?.Invoke((T) counterRoutine.Current);
}
}

Expand All @@ -77,4 +76,4 @@ internal static class HttpHeaders
public static KeyValuePair<string, string> Accept => new("Accept", "application/json");
public static KeyValuePair<string, string> UserAgent => new("User-Agent", "tezos-unity-sdk");
}
}
}

0 comments on commit 1e24310

Please sign in to comment.