Esempio n. 1
0
        /// <summary>
        /// Enqueue a callback as a work item to be invoked with the current <see cref="TaskEnv"/>.
        /// </summary>
        /// <typeparam name="T">Result value type of callback.</typeparam>
        /// <param name="dispatchQueue">DispatchQueue to enqueue work into.</param>
        /// <param name="callback">Work item callback.</param>
        /// <param name="result">Synchronization handle for work item.</param>
        /// <returns>The synchronization handle provided to the method.</returns>
        public static Result <T> QueueWorkItemWithCurrentEnv <T>(this IDispatchQueue dispatchQueue, Func <T> callback, Result <T> result)
        {
            var current = TaskEnv.CurrentOrNull;

            if (current != null)
            {
                return(dispatchQueue.QueueWorkItemWithEnv(callback, current, result));
            }
            if (result != null)
            {
                dispatchQueue.QueueWorkItem(delegate() {
                    try {
                        result.Return(callback());
                    } catch (Exception e) {
                        result.Throw(e);
                    }
                });
                return(result);
            }
            dispatchQueue.QueueWorkItem(() => callback());
            return(null);
        }
Esempio n. 2
0
        /// <summary>
        /// Enqueue a callback as a work item to be invoked with the current <see cref="TaskEnv"/>.
        /// </summary>
        /// <param name="dispatchQueue">DispatchQueue to enqueue work into.</param>
        /// <param name="callback">Work item callback.</param>
        /// <param name="result">Synchronization handle for work item.</param>
        /// <returns>The synchronization handle provided to the method.</returns>
        public static Result QueueWorkItemWithCurrentEnv(this IDispatchQueue dispatchQueue, Action callback, Result result)
        {
            var current = TaskEnv.CurrentOrNull;

            if (current != null)
            {
                return(dispatchQueue.QueueWorkItemWithEnv(callback, current, result));
            }
            if (result != null)
            {
                dispatchQueue.QueueWorkItem(() => {
                    try {
                        callback();
                        result.Return();
                    } catch (Exception e) {
                        result.Throw(e);
                    }
                });
                return(result);
            }
            dispatchQueue.QueueWorkItem(callback);
            return(null);
        }
Esempio n. 3
0
 /// <summary>
 /// Enqueue a callback as a work item to be invoked with a clone of the current <see cref="TaskEnv"/>.
 /// </summary>
 /// <param name="dispatchQueue">DispatchQueue to enqueue work into.</param>
 /// <param name="callback">Work item callback.</param>
 /// <param name="result">Synchronization handle for work item.</param>
 /// <returns>The synchronization handle provided to the method.</returns>
 public static Result QueueWorkItemWithClonedEnv(this IDispatchQueue dispatchQueue, Action callback, Result result)
 {
     return(dispatchQueue.QueueWorkItemWithEnv(callback, TaskEnv.Clone(), result));
 }
Esempio n. 4
0
 /// <summary>
 /// Enqueue a callback as a work item to be invoked with a provided <see cref="TaskEnv"/>.
 /// </summary>
 /// <param name="dispatchQueue">DispatchQueue to enqueue work into.</param>
 /// <param name="callback">Work item callback.</param>
 /// <param name="env">Environment for work item invocation.</param>
 public static void QueueWorkItemWithEnv(this IDispatchQueue dispatchQueue, Action callback, TaskEnv env)
 {
     dispatchQueue.QueueWorkItemWithEnv(callback, env, null);
 }
Esempio n. 5
0
 /// <summary>
 /// Enqueue a callback as a work item to be invoked with a clone of the current <see cref="TaskEnv"/>.
 /// </summary>
 /// <param name="dispatchQueue">DispatchQueue to enqueue work into.</param>
 /// <param name="callback">Work item callback.</param>
 public static void QueueWorkItemWithClonedEnv(this IDispatchQueue dispatchQueue, Action callback)
 {
     dispatchQueue.QueueWorkItemWithEnv(callback, TaskEnv.Clone(), null);
 }
Esempio n. 6
0
 /// <summary>
 /// Enqueue a callback as a work item to be invoked with a clone of the current <see cref="TaskEnv"/>.
 /// </summary>
 /// <typeparam name="T">Result value type of callback.</typeparam>
 /// <param name="dispatchQueue">DispatchQueue to enqueue work into.</param>
 /// <param name="callback">Work item callback.</param>
 /// <param name="result">Synchronization handle for work item.</param>
 /// <returns>The synchronization handle provided to the method.</returns>
 public static Result <T> QueueWorkItemWithClonedEnv <T>(this IDispatchQueue dispatchQueue, Func <T> callback, Result <T> result)
 {
     return(dispatchQueue.QueueWorkItemWithEnv(callback, TaskEnv.Clone(), result));
 }
Esempio n. 7
0
 /// <summary>
 /// Dispatch an action to be executed via the <see cref="GlobalDispatchQueue"/>.
 /// </summary>
 /// <param name="handler">Action to enqueue for execution.</param>
 /// <param name="env">Environment in which to execute the action.</param>
 /// <param name="result">The <see cref="Result"/>instance to be returned by this method.</param>
 /// <returns>Synchronization handle for the action's execution.</returns>
 public static Result Fork(Action handler, TaskEnv env, Result result)
 {
     return(GlobalDispatchQueue.QueueWorkItemWithEnv(handler, env, result));
 }