Testing rx with 'real' delay

本小妞迷上赌 提交于 2021-01-28 18:23:31

问题


I have been investigating the possibility of 'protecting' an observable source from a slow observer, by throwing away any new items that come in while the observer is working.

After looking at ObserveLatestOn (and finding it a bit hard to understand...), I chanced on this answer, which suggested doing it in Subscribe, rather than inside the Observable monad.

Which gives something like this (versions with delegate overloads not shown):

public static IDisposable NonBlockingSubscribe<T>(this IObservable<T> observable, 
                                                       IObserver<T> observer)
{
    Task task = null;
    return observable.Subscribe(value =>
    {
        if(task == null || task.IsCompleted)
            task = Task.Run(() => observer.OnNext(value));
    }, observer.OnError, observer.OnCompleted);
}

The challenge now is working out how to write a test for this using ReactiveTest and virtual time.

I've seen the answer to this question, which involves using TestScheduler to generate a 'ticker' which can be used in turn to create an AsyncSelector, but I'm a bit stuck working out how to go from there to something which can 'wait for a given number of ticks'.

来源:https://stackoverflow.com/questions/33296694/testing-rx-with-real-delay

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!