-
-
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
9 changed files
with
173 additions
and
128 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,35 @@ | ||
namespace R3 | ||
{ | ||
public static partial class EventFactory | ||
{ | ||
public static CompletableEvent<int, Unit> Range(int start, int count) | ||
{ | ||
return new R3.Factories.Range(start, count); | ||
} | ||
} | ||
} | ||
|
||
namespace R3.Factories | ||
{ | ||
internal sealed class Range : CompletableEvent<int, Unit> | ||
{ | ||
readonly int start; | ||
readonly int count; | ||
|
||
public Range(int start, int count) | ||
{ | ||
this.start = start; | ||
this.count = count; | ||
} | ||
|
||
protected override IDisposable SubscribeCore(Subscriber<int, Unit> subscriber) | ||
{ | ||
for (int i = 0; i < count; i++) | ||
{ | ||
subscriber.OnNext(start + i); | ||
} | ||
subscriber.OnCompleted(default); | ||
return Disposable.Empty; | ||
} | ||
} | ||
} |
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,62 @@ | ||
namespace R3 | ||
{ | ||
public static partial class EventFactory | ||
{ | ||
public static CompletableEvent<Unit, Unit> Timer(TimeSpan dueTime, TimeProvider timeProvider) | ||
{ | ||
return new R3.Factories.Timer(dueTime, timeProvider); | ||
} | ||
} | ||
} | ||
|
||
namespace R3.Factories | ||
{ | ||
internal sealed class Timer : CompletableEvent<Unit, Unit> | ||
{ | ||
readonly TimeSpan dueTime; | ||
readonly TimeProvider timeProvider; | ||
|
||
public Timer(TimeSpan dueTime, TimeProvider timeProvider) | ||
{ | ||
this.dueTime = dueTime; | ||
this.timeProvider = timeProvider; | ||
} | ||
|
||
protected override IDisposable SubscribeCore(Subscriber<Unit, Unit> subscriber) | ||
{ | ||
var method = new _Timer(subscriber); | ||
method.Timer = timeProvider.CreateStoppedTimer(_Timer.timerCallback, method); | ||
method.Timer.InvokeOnce(dueTime); | ||
return method; | ||
} | ||
|
||
sealed class _Timer(Subscriber<Unit, Unit> subscriber) : IDisposable | ||
{ | ||
public static readonly TimerCallback timerCallback = NextTick; | ||
|
||
Subscriber<Unit, Unit> subscriber = subscriber; | ||
|
||
public ITimer? Timer { get; set; } | ||
|
||
static void NextTick(object? state) | ||
{ | ||
var self = (_Timer)state!; | ||
try | ||
{ | ||
self.subscriber.OnNext(default); | ||
self.subscriber.OnCompleted(); | ||
} | ||
finally | ||
{ | ||
self.Dispose(); | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Timer?.Dispose(); | ||
Timer = null; | ||
} | ||
} | ||
} | ||
} |
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,26 @@ | ||
namespace R3 | ||
{ | ||
public static partial class EventFactory | ||
{ | ||
public static CompletableEvent<TMessage, Unit> ToEvent<TMessage>(this IEnumerable<TMessage> source) | ||
{ | ||
return new ToEvent<TMessage>(source); | ||
} | ||
} | ||
} | ||
|
||
namespace R3.Factories | ||
{ | ||
internal class ToEvent<TMessage>(IEnumerable<TMessage> source) : CompletableEvent<TMessage, Unit> | ||
{ | ||
protected override IDisposable SubscribeCore(Subscriber<TMessage, Unit> subscriber) | ||
{ | ||
foreach (var message in source) | ||
{ | ||
subscriber.OnNext(message); | ||
} | ||
subscriber.OnCompleted(default); | ||
return Disposable.Empty; | ||
} | ||
} | ||
} |
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,29 @@ | ||
namespace R3 | ||
{ | ||
// TODO: this is working space, will remove this file after complete. | ||
|
||
public static partial class EventFactory | ||
{ | ||
// TODO: Empty, Never, Throw, Defer, DeferAsync, FromAsync, FromAsyncPattern, FromEvent, FromEventPattern, Interval, Range, Repeat, Start, Timer, Using, Create | ||
|
||
// TODO: Convert | ||
// ToArray | ||
// ToAsync | ||
// ToDictionary | ||
// ToEnumerable | ||
// ToEvent | ||
// ToEventPattern | ||
// ToList | ||
// ToLookup | ||
// ToObservable | ||
|
||
// AsObservable | ||
// AsSingleUnitObservable | ||
// AsUnitObservable | ||
|
||
} | ||
} | ||
|
||
namespace R3.Factories | ||
{ | ||
} |
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,14 @@ | ||
namespace R3 | ||
{ | ||
// TODO: this is working space, will remove this file after complete. | ||
|
||
public static partial class EventExtensions | ||
{ | ||
|
||
} | ||
} | ||
|
||
namespace R3.Operators | ||
{ | ||
|
||
} |
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