public void PauseCoroutineFromAnotherThread()
        {
            var coroutineContext = new CoroutineContext(InfiniteCoroutine);

            Assert.IsFalse(coroutineContext.IsStarted);
            Assert.IsFalse(coroutineContext.IsPaused);
            Assert.IsFalse(coroutineContext.IsFinished);

            bool isPausedEventTriggered = false;

            coroutineContext.Paused += paused => isPausedEventTriggered = paused;

            var pausingThread = new Thread(() =>
            {
                Thread.Sleep(10);
                coroutineContext.Pause();
            });

            pausingThread.Start();
            coroutineContext.Start();

            Assert.IsTrue(isPausedEventTriggered);
            Assert.IsTrue(coroutineContext.IsStarted);
            Assert.IsTrue(coroutineContext.IsPaused);
            Assert.IsFalse(coroutineContext.IsFinished);

            var testUnpausedThread = new Thread(() =>
            {
                Thread.Sleep(10);

                Assert.IsTrue(coroutineContext.IsStarted);
                Assert.IsFalse(coroutineContext.IsPaused);
                Assert.IsFalse(coroutineContext.IsFinished);

                coroutineContext.Stop();
            });

            testUnpausedThread.Start();

            coroutineContext.Unpause();
        }
        public void StopCoroutineFromAnotherThread()
        {
            var coroutineContext = new CoroutineContext(InfiniteCoroutine);

            var isStoppedEventTriggered = false;

            coroutineContext.Stopped += () => isStoppedEventTriggered = true;

            var stoppingThread = new Thread(() =>
            {
                Thread.Sleep(10);
                coroutineContext.Stop();
            });

            stoppingThread.Start();
            coroutineContext.Start();

            Assert.IsTrue(isStoppedEventTriggered);
            Assert.IsFalse(coroutineContext.IsStarted);
            Assert.IsFalse(coroutineContext.IsPaused);
            Assert.IsFalse(coroutineContext.IsFinished);
        }