2012-07-27 160 views
1

鑑於此僞代碼,我想要做的是確保如果我有多個訂戶,我不會飽和我的remote源與額外輪詢每個訂閱者。如何使'Defer`ed observable只訂閱第一個訂閱者?

IObservable<data> RemoteObservable(Remote remote) 
{ 
    var onceonly = Observable.FromAsyncPattern(remote.Begin, remote.End); 
    return Observable.Defer(() => onceonly()) 
        .Repeat(); 
} 

回答

2

答案是RefCount,(發現here):

return Observable.Defer(() => onceonly()) 
        .Repeat() 
        .Publish() 
        .RefCount();