forked from idg10/prog-cs-8-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAsync.cs
35 lines (33 loc) · 1005 Bytes
/
Async.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
using System.Net.Http;
using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;
using System.Threading.Tasks;
namespace Adaptation
{
public static class Async
{
public static class FetchOnce
{
public static IObservable<string> GetWebPageAsObservable(
Uri pageUrl, IHttpClientFactory cf)
{
HttpClient web = cf.CreateClient();
Task<string> getPageTask = web.GetStringAsync(pageUrl);
return getPageTask.ToObservable();
}
}
public static class FetchPerSubscriber
{
public static IObservable<string> GetWebPageAsObservable(
Uri pageUrl, IHttpClientFactory cf)
{
return Observable.FromAsync(() =>
{
HttpClient web = cf.CreateClient();
return web.GetStringAsync(pageUrl);
});
}
}
}
}