public static Coroutine_ StartCoroutine1(MonoBehaviour b, IEnumerator <object> coroutine, object mutex = null) { var _coroutine = new Coroutine_(coroutine, mutex); _coroutine.StartWith(b); return(_coroutine); }
static void SetInUseBy(object mutex, Coroutine_ cr) { if (inUseBy == null) { inUseBy = new Dictionary <object, Coroutine_>(); } if (!inUseBy.ContainsKey(mutex)) { inUseBy.Add(mutex, cr); } else { inUseBy[mutex] = cr; } }
public static Coroutine_ StartCoroutineSingle(MonoBehaviour b, IEnumerator <object> coroutine, object mutex) { if (mutex == null) { Debug.LogWarning("Mutex is null. Consider using StartCoroutine1 instead."); return(StartCoroutine1(b, coroutine)); } if (!CoroutineMonitor.TryEnter(mutex)) { return(GetInUseBy(mutex)); } var _coroutine = new Coroutine_(coroutine, mutex, true); _coroutine.StartWith(b); return(_coroutine); }
/// <summary> /// Attempts to start a coroutine in single mode. The difference in execution order between /// this and the StartCoroutine1 with a mutex is that the mutex lock is acquired before the /// coroutine is started. If a lock on the mutex cannot be acquired, the previous coroutine /// that acquired the lock will be returned. /// /// The started coroutine allows for suspending, interrupting and resuming. The started /// coroutine is not awaitable like a Unity Coroutine. Instead, use Coroutine_.GetAwaiter() /// if you want to wait for the coroutine to complete similar to Unity's coroutines. /// /// This function works on disposable coroutines. So the finally block in the coroutine is /// guaranteed to execute. /// </summary> /// <param name="b">The MonoBehaviour that starts the coroutine.</param> /// <param name="coroutine">The Coroutine in question.</param> /// <param name="mutex">A mutex that should not be null. A warning will be issued if it is /// null and the coroutine will be started normally.</param> /// <returns></returns> public static Coroutine_ StartCoroutineSingle(this MonoBehaviour b, IEnumerator <object> coroutine, object mutex = null) { return(Coroutine_.StartCoroutineSingle(b, coroutine, mutex)); }
/// <summary> /// Starts a coroutine that allows for suspending, interrupting and resuming. The started /// coroutine is not awaitable like a Unity Coroutine. Instead, use Coroutine_.GetAwaiter() /// if you want to wait for the coroutine to complete similar to Unity's coroutines. /// /// This function works on disposable coroutines. So the finally block in the coroutine is /// guaranteed to execute. /// </summary> /// <param name="b">The MonoBehaviour that starts the coroutine.</param> /// <param name="coroutine">The Coroutine in question.</param> /// <param name="mutex">A mutex. If supplied, this mutex will be used and the coroutine is /// started in chained mode. If null, the coroutine is started normally.</param> /// <returns>A interruptable coroutine.</returns> public static Coroutine_ StartCoroutine1(this MonoBehaviour b, IEnumerable <object> coroutine, object mutex = null) { return(Coroutine_.StartCoroutine1(b, coroutine.GetEnumerator(), mutex)); }