Пример #1
0
        IEnumerator Start()
        {
            this.executor = new ThreadExecutor();

            IAsyncResult r1 = this.executor.Execute(Task1);

            yield return(r1.WaitForDone());

            IAsyncResult r2 = this.executor.Execute(promise => Task2(promise));

            yield return(r2.WaitForDone());

            IAsyncResult <string> r3 = this.executor.Execute <string> (promise => Task3(promise));

            yield return(new WaitForSeconds(0.5f));

            r3.Cancel();
            yield return(r3.WaitForDone());

            Debug.LogFormat("Task3 IsCalcelled:{0}", r3.IsCancelled);

            IProgressResult <float, string> r4 = this.executor.Execute <float, string> (promise => Task4(promise));

            while (!r4.IsDone)
            {
                yield return(null);

                Debug.LogFormat("Task4 Progress:{0}%", Mathf.FloorToInt(r4.Progress * 100));
            }

            Debug.LogFormat("Task4 Result:{0}", r4.Result);
        }
Пример #2
0
        /// <summary>
        /// Cancel a task.
        /// </summary>
        /// <returns>The cancel.</returns>
        /// <param name="result">Result.</param>
        protected IEnumerator DoCancel(IAsyncResult result)
        {
            yield return(new WaitForSeconds(3f));

            result.Cancel();
        }