예제 #1
0
        public static IAsyncObservable <TResult> ToAsyncObservable <TResult>(this Task <TResult> task)
        {
            if (task == null)
            {
                throw new ArgumentNullException(nameof(task));
            }

            return(AsyncObservable.Create <TResult>(observer => task.AcceptAsync(observer)));
        }
예제 #2
0
        public static IAsyncObservable <Unit> ToAsyncObservable(this Task task, IAsyncScheduler scheduler)
        {
            if (task == null)
            {
                throw new ArgumentNullException(nameof(task));
            }
            if (scheduler == null)
            {
                throw new ArgumentNullException(nameof(scheduler));
            }

            return(AsyncObservable.Create <Unit>(observer => task.AcceptAsync(observer, scheduler)));
        }
예제 #3
0
파일: RxCanon.cs 프로젝트: AdroDG/babble-cs
        /// <summary>
        /// Pulls the specified cancellation token.
        /// </summary>
        /// <returns></returns>
        public IAsyncObservable <TElement> PullAll()
        {
            var observable = AsyncObservable.Create <TElement>(obs =>
            {
                while (!_items.IsEmpty)
                {
                    var item = PullOne();
                    if (item == null)
                    {
                        break;
                    }
                    obs.OnNextAsync(item);
                }
                return(Task.FromResult(AsyncDisposable.Nop));
            });

            return(observable);
        }