Skip to content

Commit

Permalink
Never
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed Dec 10, 2023
1 parent cc57fcc commit 51b2d5a
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/R3/Factories/Empty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public static partial class EventFactory
{
public static CompletableEvent<TMessage, Unit> Empty<TMessage>()
{
return new Empty<TMessage>();
return R3.Factories.Empty<TMessage>.Instance;
}

public static CompletableEvent<TMessage, Unit> Empty<TMessage>(TimeProvider timeProvider)
Expand All @@ -23,11 +23,19 @@ namespace R3.Factories
{
internal sealed class Empty<TMessage> : CompletableEvent<TMessage, Unit>
{
// singleton
public static readonly Empty<TMessage> Instance = new Empty<TMessage>();

protected override IDisposable SubscribeCore(Subscriber<TMessage, Unit> subscriber)
{
subscriber.OnCompleted(default);
return Disposable.Empty;
}

Empty()
{

}
}

internal sealed class EmptyT<TMessage>(TimeSpan dueTime, TimeProvider timeProvider) : CompletableEvent<TMessage, Unit>
Expand Down
55 changes: 55 additions & 0 deletions src/R3/Factories/Never.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
namespace R3
{
public static partial class EventFactory
{
// Never
public static Event<T> Never<T>()
{
return R3.Factories.Never<T>.Instance;
}

// NeverComplete
public static CompletableEvent<TMessage, TComplete> NeverComplete<TMessage, TComplete>()
{
return R3.Factories.NeverComplete<TMessage, TComplete>.Instance;
}
}
}

namespace R3.Factories
{
// Never
internal sealed class Never<T> : Event<T>
{
// singleton
public static readonly Never<T> Instance = new Never<T>();

Never()
{

}

protected override IDisposable SubscribeCore(Subscriber<T> subscriber)
{
return Disposable.Empty;
}
}


// NeverComplete
internal sealed class NeverComplete<TMessage, TComplete> : CompletableEvent<TMessage, TComplete>
{
// singleton
public static readonly NeverComplete<TMessage, TComplete> Instance = new NeverComplete<TMessage, TComplete>();

NeverComplete()
{

}

protected override IDisposable SubscribeCore(Subscriber<TMessage, TComplete> subscriber)
{
return Disposable.Empty;
}
}
}
4 changes: 2 additions & 2 deletions src/R3/Factories/_EventFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public static partial class EventFactory
{
// TODO: this is working space, will remove this file after complete.

// TODO: Empty, Never, Throw, Defer, DeferAsync, FromAsync, FromAsyncPattern, FromEvent, FromEventPattern, Interval, Range, Repeat, Start, Timer, Using, Create
// TODO: Throw, Defer, DeferAsync, FromAsync, FromAsyncPattern, FromEvent, FromEventPattern, Interval, Range, Repeat, Start, Timer, Using, Create

// TODO: Convert
// ToArray
Expand All @@ -26,5 +26,5 @@ public static partial class EventFactory
namespace R3.Factories
{


}
19 changes: 19 additions & 0 deletions tests/R3.Tests/FactoryTests/NeverTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace R3.Tests.FactoryTests;

public class NeverTest
{
[Fact]
public void Never()
{
using var list = EventFactory.Never<int>().LiveRecord();
list.AssertIsNotCompleted();
}

// NeverComplete test
[Fact]
public void NeverComplete()
{
using var list = EventFactory.NeverComplete<int, int>().LiveRecord();
list.AssertIsNotCompleted();
}
}

0 comments on commit 51b2d5a

Please sign in to comment.