/// <summary>
        /// Cancels the top level coroutine, due to a given reason. Returns false if there is no coroutine to cancel.
        /// </summary>
        public bool CancelTopCoroutine(LoopCancelReason reason, MonoBehaviour context = null)
        {
            // Return false if the stack is empty.
            if (!HasLoopCoroutine)
            {
                return(false);
            }

            // If the coroutine was cancelled for a reason, stop the execution of it.
            if (reason != LoopCancelReason.None && context != null)
            {
                context.StopCoroutine(_coroutineStack.Peek());
            }

            // Otherwise pop the topmost element and assign the reason.
            _coroutineStack.Pop();
            LastCancelReason = reason;

            return(true);
        }
 public LoopOperationModule()
 {
     _coroutineStack  = new Stack <IEnumerator>();
     LastCancelReason = LoopCancelReason.None;
 }