コード例 #1
0
        protected IEnumerator TestInterceptMoveNextMethod()
        {
            ProgressResult <float, bool> result = new ProgressResult <float, bool>(true);

            /* Register a callback */
            result.Callbackable().OnProgressCallback(p => Debug.LogFormat("Progress:{0}%", p * 100));

            result.Callbackable().OnCallback((r) =>
            {
                Debug.LogFormat("The task is finished. IsCancelled:{0} Result:{1} Exception:{2}", r.IsCancelled, r.Result, r.Exception);
            });

            InterceptableEnumerator routine = new InterceptableEnumerator(DoTask(result));

            /* if result.IsCancellationRequested == true ,the task will be cancelled. */
            routine.RegisterConditionBlock(() => !(result.IsCancellationRequested));

            routine.RegisterFinallyBlock(() =>
            {
                Debug.Log("this is a finally block.");
            });

            /* Start the task */
            this.StartCoroutine(routine);

            yield return(new WaitForSeconds(0.5f));

            result.Cancel();
        }