-
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
154 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
namespace R3; | ||
|
||
public static partial class Observable | ||
{ | ||
public static IObservable<T> Amb<T>(params IObservable<T>[] sources) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public static IObservable<T> Amb<T>(IEnumerable<IObservable<T>> sources) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
|
||
internal sealed class Amb<T>(IEnumerable<IObservable<T>> sources) : Observable<T> | ||
{ | ||
protected override IDisposable SubscribeCore(Observer<T> observer) | ||
{ | ||
//new CompositeDiposableBuilder | ||
// Disposable.CreateBuilder(); | ||
throw new NotImplementedException(); | ||
//if (sources.TryGetNonEnumeratedCount(out var count)) | ||
//{ | ||
|
||
|
||
//} | ||
//else | ||
//{ | ||
|
||
//} | ||
// throw new NotImplementedException(); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
namespace R3.Tests; | ||
|
||
public class DisposableBuilderTest | ||
{ | ||
// 1~8 = Combined, 9~ array | ||
[Fact] | ||
public void Combined() | ||
{ | ||
// combined check | ||
for (int i = 1; i <= 8; i++) | ||
{ | ||
var l = new List<int>(); | ||
using var builder = Disposable.CreateBuilder(); | ||
for (int j = 0; j < i; j++) | ||
{ | ||
builder.Add(Disposable.Create(() => l.Add(j + 1))); | ||
} | ||
|
||
var disposable = builder.Build(); | ||
|
||
if (i == 1) | ||
{ | ||
disposable.GetType().Name.Should().Be("AnonymousDisposable"); | ||
} | ||
else | ||
{ | ||
disposable.GetType().Name.Should().StartWith("CombinedDisposable"); | ||
} | ||
|
||
l.Should().BeEmpty(); | ||
|
||
disposable.Dispose(); | ||
|
||
l.Should().HaveCount(i); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void Array() | ||
{ | ||
var l = new List<int>(); | ||
using var builder = Disposable.CreateBuilder(); | ||
for (int i = 1; i <= 8; i++) | ||
{ | ||
var v = i; | ||
builder.Add(Disposable.Create(() => l.Add(v))); | ||
} | ||
|
||
// array | ||
builder.Add(Disposable.Create(() => l.Add(9))); | ||
builder.Add(Disposable.Create(() => l.Add(10))); | ||
builder.Add(Disposable.Create(() => l.Add(11))); | ||
builder.Add(Disposable.Create(() => l.Add(12))); | ||
builder.Add(Disposable.Create(() => l.Add(13))); | ||
builder.Add(Disposable.Create(() => l.Add(14))); | ||
builder.Add(Disposable.Create(() => l.Add(15))); | ||
builder.Add(Disposable.Create(() => l.Add(16))); | ||
// grow | ||
builder.Add(Disposable.Create(() => l.Add(17))); | ||
builder.Add(Disposable.Create(() => l.Add(18))); | ||
builder.Add(Disposable.Create(() => l.Add(19))); | ||
builder.Add(Disposable.Create(() => l.Add(20))); | ||
|
||
var disposable = builder.Build(); | ||
|
||
disposable.GetType().Name.Should().Be("CombinedDisposable"); | ||
|
||
l.Should().BeEmpty(); | ||
|
||
disposable.Dispose(); | ||
|
||
l.Should().Equal([ | ||
1, | ||
2, | ||
3, | ||
4, | ||
5, | ||
6, | ||
7, | ||
8, | ||
9, | ||
10, | ||
11, | ||
12, | ||
13, | ||
14, | ||
15, | ||
16, | ||
17, | ||
18, | ||
19, | ||
20]); | ||
} | ||
|
||
} |