Rx:将多个 IObservable Web 请求拼凑在一起
我正在使用 IObservables 和反应式扩展创建多个异步 Web 请求。
因此,这为“GET”Web 请求创建了可观察的:
var tweetObservalue =
from request in WebRequestExtensions.CreateWebRequest(outUrl + querystring, method)
from response in request.GetResponseAsync()
let responseStream = response.GetResponseStream()
let reader = new StreamReader(responseStream)
select reader.ReadToEnd();
我可以
tweetObservable.Subscribe(response => dosomethingwithresponse(response));
执行使用 IObservables 和 LINQ 执行多个异步 Web 请求(必须等待其他请求完成)的正确方法是什么?
例如,首先我想验证用户信息:创建 userInfoObservable,然后如果用户信息正确,我想更新统计信息,以便获得 updateStatusObservable,然后如果状态更新,我想创建 FriendshipObservable 等等。
另外还有一个额外的问题,有一种情况我想同时执行网络调用,当所有调用完成后执行另一个可观察的,直到其他调用完成为止。
谢谢。
I'm creating multiple asynchronous web requests using IObservables and reactive extensions.
So this creates observable for "GET" web request:
var tweetObservalue =
from request in WebRequestExtensions.CreateWebRequest(outUrl + querystring, method)
from response in request.GetResponseAsync()
let responseStream = response.GetResponseStream()
let reader = new StreamReader(responseStream)
select reader.ReadToEnd();
And I can do
tweetObservable.Subscribe(response => dosomethingwithresponse(response));
What is the correct way of executing multiple asynchronous web requests with IObservables and LINQ that have to wait until other requests have been finished?
For example first I would like to verify user info: create userInfoObservable, then if user info is correct I want to update stats so I get updateStatusObservable then if status is updated I would like create friendshipObservable and so on.
Also bonus question, there is a case where I would like to execute web calls simultaneously and when all are finished execute another observable which will until other calls are finished.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是在这里回答的
http:// Social.msdn.microsoft.com/Forums/en/rx/thread/17471ab5-1ec2-4ea1-a2b3-a24cf6191820
This was answered here
http://social.msdn.microsoft.com/Forums/en/rx/thread/17471ab5-1ec2-4ea1-a2b3-a24cf6191820