コード例 #1
0
        /// <summary>
        /// Creates future from specified .Net task.
        /// Completion of this task will await with specified awaiter.
        /// </summary>
        /// <param name="awaiter">A strategy of await task completion.</param>
        /// <param name="task">A task which should be transformed to future.</param>
        /// <typeparam name="T">Type of task result.</typeparam>
        /// <returns>A future which wraps task computation results.</returns>
        public static Future <T> From <T>(IAwaiter awaiter, Task <T> task)
        {
            var promise       = new Promise <T>();
            var awaitableTask = AwaitableTask <T> .Acquire(task, promise);

            awaiter.Await(awaitableTask, awaitableTask);

            return(promise.Future);
        }
コード例 #2
0
ファイル: AwaitableTask.cs プロジェクト: drDebugIt/Agata
        private static void Release(AwaitableTask <T> awaitableTask)
        {
            awaitableTask._task    = null;
            awaitableTask._promise = null;

            if (Pool.Count < PoolSize)
            {
                Pool.Push(awaitableTask);
            }
        }
コード例 #3
0
ファイル: AwaitableTask.cs プロジェクト: drDebugIt/Agata
        public static AwaitableTask <T> Acquire(Task <T> task, Promise <T> promise)
        {
            if (!Pool.TryPop(out var awaitableTask))
            {
                awaitableTask = new AwaitableTask <T>();
            }

            awaitableTask._task    = task;
            awaitableTask._promise = promise;

            return(awaitableTask);
        }