public static IObservable <T> DelayFrame <T>(this IObservable <T> source, int frameCount, FrameCountType frameCountType = FrameCountType.Update) { if (frameCount < 0) { throw new ArgumentOutOfRangeException("frameCount"); } return(Observable.Create <T>(observer => { var cancel = new BooleanDisposable(); source.Materialize().Subscribe(x => { if (x.Kind == NotificationKind.OnError) { observer.OnError(x.Exception); cancel.Dispose(); return; } UnityMainThreadDispatcher.StartCoroutine(DelayFrameCore(() => x.Accept(observer), frameCount, frameCountType, cancel)); }); return cancel; })); }
/// <summary>AutoStart observable as coroutine.</summary> public static Coroutine StartAsCoroutine <T>(this IObservable <T> source, Action <T> onResult, Action <Exception> onError, CancellationToken cancel = default(CancellationToken)) { return(UnityMainThreadDispatcher.StartCoroutine(source.ToAwaitableEnumerator(onResult, onError, cancel))); }
public static Coroutine WhenAll(IEnumerable <LazyTask> tasks) { var coroutines = tasks.Select(x => x.Start()).ToArray(); return(UnityMainThreadDispatcher.StartCoroutine(WhenAllCore(coroutines))); }