Esempio n. 1
0
        /// <summary>Convert to awaitable IEnumerator.</summary>
        public static IEnumerator ToAwaitableEnumerator <T>(this IObservable <T> source, Action <T> onResult, Action <Exception> onError, CancellationToken cancel = default(CancellationToken))
        {
            var enumerator = new ObservableYieldInstruction <T>(source, false, cancel);
            var e          = (IEnumerator <T>)enumerator;

            while (e.MoveNext() && !cancel.IsCancellationRequested)
            {
                yield return(null);
            }

            if (cancel.IsCancellationRequested)
            {
                enumerator.Dispose();
                yield break;
            }

            if (enumerator.HasResult)
            {
                onResult(enumerator.Result);
            }
            else if (enumerator.HasError)
            {
                onError(enumerator.Error);
            }
        }
Esempio n. 2
0
 public ToYieldInstruction(ObservableYieldInstruction <T> parent)
 {
     this.parent = parent;
 }