Exemplo n.º 1
0
        /// <summary>
        ///     Creates a continuation that executes when the target <see cref="CoroutineTask" /> completes.
        /// </summary>
        /// <param name="continuationAction">
        ///     An action to run when the <see cref="CoroutineTask" /> completes.
        /// </param>
        /// <param name="continuationOptions">
        ///     Options for when the continuation is scheduled and how it behaves. This includes criteria, such
        ///     as <see cref="CoroutineTaskContinuationOptions.OnCanceled">OnCanceled</see>
        ///     , as well as execution options, such as
        ///     <see cref="CoroutineTaskContinuationOptions.OnCompleted">OnCompleted</see>.
        /// </param>
        /// <returns>A new continuation <see cref="CoroutineTask" />.</returns>
        /// <remarks>
        ///     The returned <see cref="CoroutineTask" /> will not be scheduled for execution until the current task has
        ///     completed.
        /// </remarks>
        public CoroutineTask ContinueWith(Action continuationAction,
                                          CoroutineTaskContinuationOptions continuationOptions = CoroutineTaskContinuationOptions.None)
        {
            AsyncResult result = new AsyncResult(true);

            asyncResult.Callbackable().OnCallback(ar =>
            {
                try
                {
                    var executable = IsExecutable(ar, continuationOptions);
                    if (!executable)
                    {
                        result.SetCancelled();
                        return;
                    }

                    continuationAction();
                    result.SetResult();
                }
                catch (Exception e)
                {
                    result.SetException(e);
                }
            });
            return(new CoroutineTask(result));
        }
Exemplo n.º 2
0
 public virtual ICallbackable Callbackable()
 {
     return(result.Callbackable());
 }