Aiursoft.AiurObserver 8.0.10

dotnet add package Aiursoft.AiurObserver --version 8.0.10                
NuGet\Install-Package Aiursoft.AiurObserver -Version 8.0.10                
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="Aiursoft.AiurObserver" Version="8.0.10" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Aiursoft.AiurObserver --version 8.0.10                
#r "nuget: Aiursoft.AiurObserver, 8.0.10"                
#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 Aiursoft.AiurObserver as a Cake Addin
#addin nuget:?package=Aiursoft.AiurObserver&version=8.0.10

// Install Aiursoft.AiurObserver as a Cake Tool
#tool nuget:?package=Aiursoft.AiurObserver&version=8.0.10                

AiurObserver

MIT licensed Pipeline stat Test Coverage NuGet version (Aiursoft.AiurObserver) ManHours

AiurObserver is a powerful C# development tool that allows you to construct an object that can be observed asynchronously. It comes with a set of operators that make it easy for you to manipulate and process data streams.

Call Subscribe() to subscribe to an observable. Call BroadcastAsync() to broadcast a message to all subscribers. That's it!

structure

How to install

dotnet add package Aiursoft.AiurObserver

Key Features

  • Asynchronous Observation: AiurObserver provides an AsyncObservable interface. You can create an object that can be observed asynchronously and subscribe to it.
  • Subscription Operation: When observing, you need to pass in a Consumer. The consumer is essentially a function that defines what the consumer should do when the source of the subscription pushes.
  • Data Stream Manipulation: It provides a set of operators such as Filter, Map, Throttle, Repeat, Sample, Aggregate, etc., that can easily manipulate data streams.
  • Subscription Cancellation: If you don't want to consume anymore, you can simply cancel the subscription.

Use Cases

AiurObserver is particularly suitable for the following scenarios:

  • Running Commands: Occasionally it will output two lines, but it's uncertain when it will write. I need to subscribe to its output.
  • WebSocket Remote: Occasionally something might spit in, but it's uncertain when it will spit in. When it does spit in, I need to take action.
  • A game of chess: Players will take actions to change its state. It's uncertain when the chessboard will change; but when it really changes, I also need to execute custom code.
  • Event Generators: It's uncertain when an event will occur, but once an event occurs, I need to perform certain operations.

How to use

It's very simple. You can create a class extends AsyncObservable<T> and then you can subscribe to it and broadcast messages to it.

T is the type of the message you want to broadcast.

If you no longer need to subscribe to the observable, you can call UnRegister method to unsubscribe.

Full example:

var totalMessages = 0;
var asyncObservable = new AsyncObservable<int>();
var subscription = asyncObservable.Subscribe(_ =>
{
    totalMessages++;
    return Task.CompletedTask;
});
for (var i = 0; i < 10; i++)
{
    await asyncObservable.BroadcastAsync(2333);
}

Console.WriteLine(totalMessages); // 10
subscription.Unsubscribe(); // No longer receive messages.

Why it's not IEnumerable or Stream

While AiurObserver might seem similar to IEnumerable or Stream, it's not a substitute for either.

  • IEnumerable: IEnumerable is a pull-based model. The consumer requests the next item. With AiurObserver, it's a push-based model. The producer pushes the data when it's available. This makes AiurObserver more suitable for real-time data and event-driven scenarios.

  • Stream: Stream is designed for byte data and is often used for reading and writing to a file or network stream. AiurObserver, on the other hand, is designed for object data and is more suitable for scenarios where data is produced and consumed asynchronously.

Read document

Please click here to learn how to use it.

How to contribute

There are many ways to contribute to the project: logging bugs, submitting pull requests, reporting issues, and creating suggestions.

Even if you with push rights on the repository, you should create a personal fork and create feature branches there when you need them. This keeps the main repository clean and your workflow cruft out of sight.

We're also interested in your feedback on the future of this project. You can submit a suggestion or feature request through the issue tracker. To make this process more effective, we're asking that these include more information to help define them more clearly.

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 (7)

Showing the top 5 NuGet packages that depend on Aiursoft.AiurObserver:

Package Downloads
Aiursoft.Stargate.SDK

Nuget package of 'SDK' provided by Aiursoft

Aiursoft.AiurEventSyncer.Abstract

Nuget package of 'Abstract' provided by Aiursoft

Aiursoft.AiurObserver.WebSocket

Nuget package of 'WebSocket' provided by Aiursoft

Aiursoft.AiurObserver.Extensions

AiurObserver is an async event driven framework.

Aiursoft.AiurObserver.Command

Nuget package of 'Command' provided by Aiursoft

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Aiursoft.AiurObserver:

Repository Stars
AiursoftWeb/Infrastructures
Mirror of: https://gitlab.aiursoft.cn/aiursoft/infrastructures
Version Downloads Last updated
8.0.10 29 11/30/2024
8.0.9 175 11/19/2024
8.0.8 177 11/13/2024
8.0.4 216 11/12/2024
8.0.3 349 10/7/2024
8.0.2 313 6/6/2024
8.0.1 137 6/3/2024
8.0.0 1,122 2/19/2024
7.0.26 513 2/16/2024
7.0.25 570 2/14/2024
7.0.23 852 2/2/2024
7.0.21 1,033 1/18/2024
7.0.19 764 1/9/2024
7.0.18 1,082 1/5/2024
7.0.16 386 1/5/2024
7.0.15 402 1/4/2024
7.0.12 1,296 1/4/2024
7.0.11 381 1/4/2024
7.0.10 380 1/4/2024
7.0.9 732 1/4/2024
7.0.7 354 1/3/2024
7.0.6 1,385 12/11/2023
7.0.5 856 12/11/2023
7.0.4 758 12/9/2023
7.0.3 482 11/28/2023
7.0.1 801 11/2/2023
7.0.0 1,007 9/5/2023
0.0.1 1,164 8/20/2023