Skip to content

Commit

Permalink
now working......
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed Dec 13, 2023
1 parent 53ec1e6 commit 5a4ac09
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
70 changes: 70 additions & 0 deletions src/R3/Factories/_EventFactory.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

using System.Diagnostics.CodeAnalysis;
using System.Threading;

namespace R3
{
Expand All @@ -26,10 +27,79 @@ public static partial class Event
// AsNeverComplete


//public static Event<Unit> EveryUpdate(FrameProvider frameProvider)
//{
// return new R3.Factories.EveryUpdate(frameProvider);
//}

//public static CompletableEvent<Unit> EveryUpdate(FrameProvider frameProvider, CancellationToken cancellationToken)
//{
// return new R3.Factories.EveryUpdate(frameProvider);
//}
}
}

namespace R3.Factories
{
internal sealed class EveryUpdate(FrameProvider frameProvider, CancellationToken cancellationToken) : Event<Unit>
{
protected override IDisposable SubscribeCore(Subscriber<Unit> subscriber)
{
var runner = new EveryUpdateRunnerWorkItem(subscriber, cancellationToken);
frameProvider.Register(runner);
return runner;
}

class EveryUpdateRunnerWorkItem(Subscriber<Unit> 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<Unit>
//{
// protected override IDisposable SubscribeCore(Subscriber<Unit> subscriber)
// {
// var runner = new EveryUpdateRunnerWorkItem(subscriber, cancellationToken);
// frameProvider.Register(runner);
// return runner;
// }

// class EveryUpdateRunnerWorkItem(Subscriber<Unit> 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;
// }
// }
//}
}
2 changes: 2 additions & 0 deletions src/R3/ReactiveProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

namespace R3;

// TODO: call OnCompleted on Dispose.

public abstract class ReadOnlyReactiveProperty<T> : Event<T>
{
public abstract T CurrentValue { get; }
Expand Down

0 comments on commit 5a4ac09

Please sign in to comment.