Skip to content

Commit cfe441d

Browse files
committed
+ UniRx
1 parent 3e772c2 commit cfe441d

File tree

448 files changed

+37418
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

448 files changed

+37418
-0
lines changed

Core/Dependencies/UniRx/ReadMe.txt

Lines changed: 1088 additions & 0 deletions
Large diffs are not rendered by default.

Core/Dependencies/UniRx/ReadMe.txt.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Core/Dependencies/UniRx/Scripts.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Core/Dependencies/UniRx/Scripts/Asynchronous.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Net;
6+
using System.Text;
7+
using System.Threading;
8+
9+
namespace UniRx
10+
{
11+
public static class WebRequestExtensions
12+
{
13+
static IObservable<TResult> AbortableDeferredAsyncRequest<TResult>(Func<AsyncCallback, object, IAsyncResult> begin, Func<IAsyncResult, TResult> end, WebRequest request)
14+
{
15+
var result = Observable.Create<TResult>(observer =>
16+
{
17+
var isCompleted = -1;
18+
var subscription = Observable.FromAsyncPattern<TResult>(begin,
19+
ar =>
20+
{
21+
try
22+
{
23+
Interlocked.Increment(ref isCompleted);
24+
return end(ar);
25+
}
26+
catch (WebException ex)
27+
{
28+
if (ex.Status == WebExceptionStatus.RequestCanceled) return default(TResult);
29+
throw;
30+
}
31+
})()
32+
.Subscribe(observer);
33+
return Disposable.Create(() =>
34+
{
35+
if (Interlocked.Increment(ref isCompleted) == 0)
36+
{
37+
subscription.Dispose();
38+
request.Abort();
39+
}
40+
});
41+
});
42+
43+
return result;
44+
}
45+
46+
public static IObservable<WebResponse> GetResponseAsObservable(this WebRequest request)
47+
{
48+
return AbortableDeferredAsyncRequest<WebResponse>(request.BeginGetResponse, request.EndGetResponse, request);
49+
}
50+
51+
public static IObservable<HttpWebResponse> GetResponseAsObservable(this HttpWebRequest request)
52+
{
53+
return AbortableDeferredAsyncRequest<HttpWebResponse>(request.BeginGetResponse, ar => (HttpWebResponse)request.EndGetResponse(ar), request);
54+
}
55+
56+
public static IObservable<Stream> GetRequestStreamAsObservable(this WebRequest request)
57+
{
58+
return AbortableDeferredAsyncRequest<Stream>(request.BeginGetRequestStream, request.EndGetRequestStream, request);
59+
}
60+
}
61+
}

Core/Dependencies/UniRx/Scripts/Asynchronous/WebRequestExtensions.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Core/Dependencies/UniRx/Scripts/Disposables.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Collections;
3+
4+
namespace UniRx
5+
{
6+
public class BooleanDisposable : IDisposable, ICancelable
7+
{
8+
public bool IsDisposed { get; private set; }
9+
10+
public BooleanDisposable()
11+
{
12+
13+
}
14+
15+
internal BooleanDisposable(bool isDisposed)
16+
{
17+
IsDisposed = isDisposed;
18+
}
19+
20+
public void Dispose()
21+
{
22+
if (!IsDisposed) IsDisposed = true;
23+
}
24+
}
25+
}

Core/Dependencies/UniRx/Scripts/Disposables/BooleanDisposable.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)