diff --git a/src/R3/Factories/_EventFactory.cs b/src/R3/Factories/_EventFactory.cs index 092bc5a5..c7924cf6 100644 --- a/src/R3/Factories/_EventFactory.cs +++ b/src/R3/Factories/_EventFactory.cs @@ -1,5 +1,6 @@  using System.Diagnostics.CodeAnalysis; +using System.Threading; namespace R3 { @@ -26,10 +27,79 @@ public static partial class Event // AsNeverComplete + //public static Event EveryUpdate(FrameProvider frameProvider) + //{ + // return new R3.Factories.EveryUpdate(frameProvider); + //} + + //public static CompletableEvent EveryUpdate(FrameProvider frameProvider, CancellationToken cancellationToken) + //{ + // return new R3.Factories.EveryUpdate(frameProvider); + //} } } namespace R3.Factories { + internal sealed class EveryUpdate(FrameProvider frameProvider, CancellationToken cancellationToken) : Event + { + protected override IDisposable SubscribeCore(Subscriber subscriber) + { + var runner = new EveryUpdateRunnerWorkItem(subscriber, cancellationToken); + frameProvider.Register(runner); + return runner; + } + + class EveryUpdateRunnerWorkItem(Subscriber subscriber, CancellationToken cancellationToken) : IFrameRunnerWorkItem, IDisposable + { + bool isDisposed; + + public bool MoveNext(long frameCount) + { + if (isDisposed || cancellationToken.IsCancellationRequested) + { + return false; + } + + subscriber.OnNext(default); + return true; + } + + public void Dispose() + { + isDisposed = true; + } + } + } + + //internal sealed class EveryUpdate(FrameProvider frameProvider, CancellationToken cancellationToken) : Event + //{ + // protected override IDisposable SubscribeCore(Subscriber subscriber) + // { + // var runner = new EveryUpdateRunnerWorkItem(subscriber, cancellationToken); + // frameProvider.Register(runner); + // return runner; + // } + + // class EveryUpdateRunnerWorkItem(Subscriber subscriber, CancellationToken cancellationToken) : IFrameRunnerWorkItem, IDisposable + // { + // bool isDisposed; + + // public bool MoveNext(long frameCount) + // { + // if (isDisposed || cancellationToken.IsCancellationRequested) + // { + // return false; + // } + + // subscriber.OnNext(default); + // return true; + // } + // public void Dispose() + // { + // isDisposed = true; + // } + // } + //} } diff --git a/src/R3/ReactiveProperty.cs b/src/R3/ReactiveProperty.cs index f4d2a90a..e42163d8 100644 --- a/src/R3/ReactiveProperty.cs +++ b/src/R3/ReactiveProperty.cs @@ -3,6 +3,8 @@ namespace R3; +// TODO: call OnCompleted on Dispose. + public abstract class ReadOnlyReactiveProperty : Event { public abstract T CurrentValue { get; }