2013-03-11 61 views
30

This page on MSDN指出每個可觀察運營商的默認調度器是什麼?

如果不使用,這需要調度爲參數的過載,Rx將使用最小的併發的原則選擇默認的調度。這意味着選擇引入滿足操作員需求的最少併發量的調度器。例如,對於運算符返回具有有限和少量消息的觀察值,Rx調用Immediate。對於運算符返回可能大或無限數量的消息,調用CurrentThread。對於使用定時器的運算符,使用ThreadPool。

我想實際上有一個參考表,其中可觀察到的操作員使用哪個默認調度程序,但我找不到任何地方。 每個可觀察運營商的默認調度器是什麼?

+1

我很驚訝居然有ISN」列表某處...如果我有一些時間來傾倒它,我會通過rx代碼庫,看看我是否可以編譯一個列表,但不,我沒有意識到任何浮動的網... ... – JerKimball 2013-03-13 16:50:33

+0

是的,我也在尋找,無濟於事。其中有些是顯而易見的,但有些確實不是! – AlexFoxGill 2013-03-13 17:34:00

回答

46

哇,這是不平凡的發現......

System.Reactive.Concurrency命名空間的腸子內深處,有一個名爲SchedulerDefaults內部靜態類,其聲明爲:

internal static class SchedulerDefaults 
{ 
    internal static IScheduler AsyncConversions 
    { get { return DefaultScheduler.Instance; }} 

    internal static IScheduler ConstantTimeOperations 
    { get { return ImmediateScheduler.Instance; }} 

    internal static IScheduler Iteration 
    { get { return CurrentThreadScheduler.Instance; }} 

    internal static IScheduler TailRecursion 
    { get { return ImmediateScheduler.Instance; }} 

    internal static IScheduler TimeBasedOperations 
    { get { return DefaultScheduler.Instance; }} 
} 

AsyncConversions使用由:

Start, ToAsync, FromAsyncPattern 

ConstantTimeOperations使用由:

Empty, GetSchedulerForCurrentContext, Return, StartWith, Throw 

Iteration所使用的:

Generate, Range, Repeat, TakeLast, ToObservable, and the ReplaySubject<T> 

TailRecursion所使用的:

Run 

TimeBasedOperations所使用的:

Buffer, Delay, DelaySubscription, Generate, Interval, Sample, Skip, SkipLast 
SkipUntil, Take, TakeLast, TakeLastBuffer, TakeUntil, Throttle, TimeInterval, 
Timeout, Timer, Timestamp, Window 
+0

完美,謝謝! – AlexFoxGill 2013-03-14 09:13:36

+1

理想情況下,當您使用這些方法中的任何一種時,您都可以傳遞自己的調度程序,以便您可以單元測試您的代碼。但是知道哪一個最好用,總是很好,所以這份清單非常適合! – 2013-03-22 18:17:52

+0

@LeeCampbell我個人非常驚訝於我不得不挖掘它以發現它...... sheesh。同意100%「使用你自己該死的日程安排」,壽。 – JerKimball 2013-03-22 18:20:47