コード例 #1
0
        /// <summary>
        /// Repeats given action until the given task/awaitable completes.
        /// The optional final action gets called with the task's result.
        /// </summary>
        public static async Task RepeatUntilCompleted <T>(this IAwaitable <T> self, Func <Task> action, Func <T, Task> finallyAction = null)
        {
            while (!self.IsCompleted)
            {
                await Await.WhenAny(action().AsAwaitable(), self);
            }

            if (finallyAction != null)
            {
                await finallyAction(self.Result);
            }
        }
コード例 #2
0
        /// <summary>
        /// Repeats given action until the given task/awaitable completes.
        /// </summary>
        public static async Task RepeatUntilCompleted(this IAwaitable self, Func <Task> action, Action finallyAction)
        {
            while (!self.IsCompleted)
            {
                await Await.WhenAny(action().AsAwaitable(), self);
            }

            if (finallyAction != null)
            {
                finallyAction();
            }
        }
コード例 #3
0
        static async void Run(Awaitable <int> a, Awaitable <int> b, CancellationToken ct)
        {
            try
            {
                var i = await Await.WhenAny(a, b).WithCancellation(ct);

                Console.WriteLine("got: {0}", i);
            }
            catch (OperationCanceledException)
            {
                Report.Line("cancelled");
            }
        }
コード例 #4
0
        /// <summary>
        /// Repeats given action until the next value of this event source arrives.
        /// The optional final action gets called with this newly arrived value.
        /// </summary>
        public static async Task RepeatUntilNext <T>(this IEvent <T> self, Func <Task> action, Action <T> finallyAction)
        {
            var next = self.Next;

            while (!next.IsCompleted)
            {
                await Await.WhenAny(action().AsAwaitable(), next);
            }

            if (finallyAction != null)
            {
                finallyAction(next.Result);
            }
        }