Skip to content

Commit

Permalink
chore: GlobalCoroutine.IsDestroyed check added for the Coroutine utility
Browse files Browse the repository at this point in the history
  • Loading branch information
stan-osipov committed Jul 17, 2024
1 parent 15b85d3 commit 252d4ed
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Runtime/Async/Coroutine/CoroutineUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public static Coroutine Start(IEnumerator routine)
/// <param name="routine">The <see cref="IEnumerator"/> routine you would like to stop.</param>
public static void Stop(IEnumerator routine)
{
if(GlobalCoroutine.IsDestroyed)
return;

GlobalCoroutine.Instance.StopCoroutine(routine);
}

Expand All @@ -50,6 +53,9 @@ public static void Stop(IEnumerator routine)
/// <param name="routine">The <see cref="Coroutine"/> to stop the manually created <see cref="Coroutine"/></param>
public static void Stop(Coroutine routine)
{
if(GlobalCoroutine.IsDestroyed)
return;

GlobalCoroutine.Instance.StopCoroutine(routine);
}

Expand All @@ -60,6 +66,9 @@ public static void Stop(Coroutine routine)
/// <param name="action">The callback action.</param>
public static void WaitForEndOfFrame(Action action)
{
if(GlobalCoroutine.IsDestroyed)
return;

GlobalCoroutine.Instance.StartInstruction(new WaitForEndOfFrame(), action);
}

Expand All @@ -70,6 +79,9 @@ public static void WaitForEndOfFrame(Action action)
/// </summary>
public static void WaitForFixedUpdate(Action action)
{
if(GlobalCoroutine.IsDestroyed)
return;

GlobalCoroutine.Instance.StartInstruction(new WaitForFixedUpdate(), action);
}

Expand All @@ -81,6 +93,9 @@ public static void WaitForFixedUpdate(Action action)
/// </summary>
public static void WaitForSeconds(float seconds, Action action)
{
if(GlobalCoroutine.IsDestroyed)
return;

GlobalCoroutine.Instance.StartInstruction(new WaitForSeconds(seconds), action);
}

Expand All @@ -92,6 +107,9 @@ public static void WaitForSeconds(float seconds, Action action)
/// <param name="action">The callback action.</param>
public static void WaitForSecondsRealtime(float seconds, Action action)
{
if(GlobalCoroutine.IsDestroyed)
return;

GlobalCoroutine.Instance.StartInstruction(new WaitForSecondsRealtime(seconds), action);
}

Expand All @@ -103,6 +121,9 @@ public static void WaitForSecondsRealtime(float seconds, Action action)
/// <param name="action">The callback action.</param>
public static void WaitForSecondsWithRandomInterval(float min, float max, Action action)
{
if(GlobalCoroutine.IsDestroyed)
return;

var delay = UnityEngine.Random.Range(min, max);
WaitForSeconds(delay, action);
}
Expand Down

0 comments on commit 252d4ed

Please sign in to comment.