Beispiel #1
0
        /// <summary>
        /// Creates a new ThreadTask (that returns a result) to execute work on a new thread, and then invokes a callback when the task is complete. Tasks are thread-safe provided the work being done is thread safe itself.
        /// </summary>
        /// <typeparam name="T">The type of result that the work returns</typeparam>
        /// <param name="work">The action to perform on the new thread</param>
        /// <param name="completionCallback">A callback that is invoked when the task is complete. Recieves the task result as a parameter</param>
        /// <returns>The ThreadTask</returns>
        public static ThreadTask <T> Start(Func <T> work, Action <T> completionCallback)
        {
            ThreadTask <T> task = new ThreadTask <T>(work);

            CoroutineUtils.StartCoroutine(WaitForTask(task, completionCallback));
            return(task);
        }
Beispiel #2
0
        protected static IEnumerator WaitForTask(ThreadTask <T> task, Action <T> callback)
        {
            yield return(task.WaitForCompletion());

            callback(task.Result);
        }