LfrlAnvil.Reactive.Queues 0.2.1

dotnet add package LfrlAnvil.Reactive.Queues --version 0.2.1                
NuGet\Install-Package LfrlAnvil.Reactive.Queues -Version 0.2.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LfrlAnvil.Reactive.Queues" Version="0.2.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LfrlAnvil.Reactive.Queues --version 0.2.1                
#r "nuget: LfrlAnvil.Reactive.Queues, 0.2.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install LfrlAnvil.Reactive.Queues as a Cake Addin
#addin nuget:?package=LfrlAnvil.Reactive.Queues&version=0.2.1

// Install LfrlAnvil.Reactive.Queues as a Cake Tool
#tool nuget:?package=LfrlAnvil.Reactive.Queues&version=0.2.1                

(root) NuGet Badge

LfrlAnvil.Reactive.Queues

This project contains a few functionalities related to event queues.

Documentation

Technical documentation can be found here.

Examples

Following is an example of an event queue:

// represents a datetime-related event queue with events of 'string' type
public class EventQueue : EventQueueBase<string, DateTime, TimeSpan>
{
    public EventQueue(DateTime startPoint)
        : base( startPoint ) { }

    protected override DateTime AddDelta(DateTime point, TimeSpan delta)
    {
        return point + delta;
    }
}

// creates a new event queue with its start point equal to now
var start = DateTime.Now;
var queue = new EventQueue( start );

// enqueues a single 'foo' event that should be dequeued at 'start + 2 minutes'
queue.Enqueue(
    "foo",
    delta: TimeSpan.FromMinutes( 2 ) );

// enqueues three 'bar' events that should be dequeued at:
// 1. 'start + 1 minute'
// 2. 'start + 6 minutes'
// 3. 'start + 11 minutes'
queue.EnqueueAt(
    "bar",
    dequeuePoint: start + TimeSpan.FromMinutes( 1 ),
    delta: TimeSpan.FromMinutes( 5 ),
    repetitions: 3 );

// enqueues an infinite number of 'qux' events that should be dequeued at:
// 1. 'start + 4 minutes'
// 2. 'start + 8 minutes'
// 3. 'start + 12 minutes'
// 4. 'start + 16 minutes'
// etc.
queue.EnqueueInfinite(
    "qux",
    delta: TimeSpan.FromMinutes( 4 ) );

// moves the queue forward by '7 minutes'
queue.Move( TimeSpan.FromMinutes( 7 ) );

// dequeues all pending events
for ( var e = queue.Dequeue(); e is not null; e = queue.Dequeue() )
    Console.WriteLine( $"Event: '{e.Value.Event}', Offset: {e.Value.DequeuePoint - start}" );

// expected console output:
// Event: 'bar', Offset: 00:01:00
// Event: 'foo', Offset: 00:02:00
// Event: 'qux', Offset: 00:04:00
// Event: 'bar', Offset: 00:06:00

// moves the queue forward by '10 minutes', to 'start + 17 minutes' point
queue.Move( TimeSpan.FromMinutes( 10 ) );

// dequeues all pending events
for ( var e = queue.Dequeue(); e is not null; e = queue.Dequeue() )
    Console.WriteLine( $"Event: '{e.Value.Event}', Offset: {e.Value.DequeuePoint - start}" );

// expected console output:
// Event: 'qux', Offset: 00:08:00
// Event: 'bar', Offset: 00:11:00
// Event: 'qux', Offset: 00:12:00
// Event: 'qux', Offset: 00:16:00

There also exists an event queue version that allows to re-organize registered events.

Following is an example of an event stream based on an event queue:

// creates a new event stream based on an event queue with its start point equal to now
var start = DateTime.Now;
var source = QueueEventSource.Create( new EventQueue( start ) );

// attaches a listener to the event stream
source.Listen(
    EventListener.Create<FromQueue<string, DateTime, TimeSpan>>(
        e => Console.WriteLine( $"Event: '{e.Enqueued.Event}', Offset: {e.Enqueued.DequeuePoint - start}" ) ) );

// enqueues a single 'foo' event that should be dequeued at 'start + 2 minutes'
source.Queue.Enqueue(
    "foo",
    delta: TimeSpan.FromMinutes( 2 ) );

// enqueues three 'bar' events that should be dequeued at:
// 1. 'start + 1 minute'
// 2. 'start + 6 minutes'
// 3. 'start + 11 minutes'
source.Queue.EnqueueAt(
    "bar",
    dequeuePoint: start + TimeSpan.FromMinutes( 1 ),
    delta: TimeSpan.FromMinutes( 5 ),
    repetitions: 3 );

// enqueues an infinite number of 'qux' events that should be dequeued at:
// 1. 'start + 4 minutes'
// 2. 'start + 8 minutes'
// 3. 'start + 12 minutes'
// 4. 'start + 16 minutes'
// etc.
source.Queue.EnqueueInfinite(
    "qux",
    delta: TimeSpan.FromMinutes( 4 ) );

// moves the event stream forward by '7 minutes'
source.Move( TimeSpan.FromMinutes( 7 ) );

// expected console output:
// Event: 'bar', Offset: 00:01:00
// Event: 'foo', Offset: 00:02:00
// Event: 'qux', Offset: 00:04:00
// Event: 'bar', Offset: 00:06:00

// moves the event stream forward by '10 minutes', to 'start + 17 minutes' point
source.Move( TimeSpan.FromMinutes( 10 ) );

// expected console output:
// Event: 'qux', Offset: 00:08:00
// Event: 'bar', Offset: 00:11:00
// Event: 'qux', Offset: 00:12:00
// Event: 'qux', Offset: 00:16:00
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on LfrlAnvil.Reactive.Queues:

Package Downloads
LfrlAnvil.Reactive.Chrono

This project contains a few functionalities related to timers and schedulers.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.2.1 132 6/16/2024
0.2.0 141 6/16/2024
0.1.1 111 5/29/2024
0.1.0 124 5/26/2024