RX: Best approach to async download a list of some

2019-08-19 18:14发布

The result Im after is a list (WPF) of items that is populated one at a time async from a web service (WCF). I figured RX could be a good option for this?

My web service method is returning an array of strings (for now) and at the client-side Im using:

var list = Observable.FromAsyncPattern<string[]>(client.BeginList, client.EndList);

But now what? Im not familiar with RX at all and I feel very lost. Anyhow I guess my web service has to stream the list instead of sending it in a chunk if I want them to pop in continously?

1条回答
太酷不给撩
2楼-- · 2019-08-19 18:17

FromObservablePattern returns a Func<IObservable> (or possibly with arguments if the service takes any), so you call the delegate and then subscribe to the source:

var list = Observable.FromAsyncPattern<string[]>(client.BeginList, client.EndList);

list().Subscribe(items =>
{
    // items is the string[]
});
查看更多
登录 后发表回答