public Coroutine(string lockID, float waitTime, LockQueue lockedCoroutines) { this.lockable = true; this.lockID = lockID; this.lockedCoroutines = lockedCoroutines; this.waitTime = waitTime; }
public void TestWriteRead() { LockQueue queue = new LockQueue(); queue.LockNoWait("lock1", LockType.Write); Assert.AreEqual(queue.Length, 1); queue.LockNoWait("lock2", LockType.Read); Assert.AreEqual(queue.Length, 1); }
/// <summary> /// Lockable coroutine. Can either wait for a previous coroutine to finish or a timeout or just bail if previous one isn't done. /// Caution: the default timeout is 10 seconds. Coroutines that timeout just drop so if its essential increase this timeout. /// Set waitTime to 0 for no wait /// </summary> public static Coroutine <T> StartCoroutine <T>(this MonoBehaviour mb, IEnumerator coroutine, string lockID, float waitTime = 10f) { if (!LockedCoroutineQueues.ContainsKey(mb)) { LockedCoroutineQueues[mb] = new LockQueue(); } Coroutine <T> coroutineObj = new Coroutine <T>(lockID, waitTime, LockedCoroutineQueues[mb]); coroutineObj.coroutine = mb.StartCoroutine(coroutineObj.InternalRoutine(coroutine)); return(coroutineObj); }
/// <summary> /// Lockable coroutine. Can either wait for a previous coroutine to finish or a timeout or just bail if previous one isn't done. /// Caution: the default timeout is 10 seconds. Coroutines that timeout just drop so if its essential increase this timeout. /// Set waitTime to 0 for no wait /// </summary> public Coroutine <T> StartCoroutine <T>(IEnumerator coroutine, string lockID, float waitTime = 10f) { if (LockedCoroutineQueue == null) { LockedCoroutineQueue = new LockQueue(); } Coroutine <T> coroutineObj = new Coroutine <T>(lockID, waitTime, LockedCoroutineQueue); coroutineObj.coroutine = base.StartCoroutine(coroutineObj.InternalRoutine(coroutine)); return(coroutineObj); }
public void TestAddAndRemove() { LockQueue queue = new LockQueue(); queue.LockNoWait("lock1", LockType.Read); Assert.AreEqual(queue.Length, 1); queue.LockNoWait("lock2", LockType.Read); Assert.AreEqual(queue.Length, 2); queue.Unlock("lock2"); Assert.AreEqual(queue.Length, 2); queue.Unlock("lock1"); Assert.AreEqual(queue.Length, 0); }