Fibrous 6.0.0
dotnet add package Fibrous --version 6.0.0
NuGet\Install-Package Fibrous -Version 6.0.0
<PackageReference Include="Fibrous" Version="6.0.0" />
paket add Fibrous --version 6.0.0
#r "nuget: Fibrous, 6.0.0"
// Install Fibrous as a Cake Addin #addin nuget:?package=Fibrous&version=6.0.0 // Install Fibrous as a Cake Tool #tool nuget:?package=Fibrous&version=6.0.0
Fibrous
High performance concurrency library for the .Net platform. Fibrous is a fork of Retlang [http://code.google.com/p/retlang/].
Fibrous is an actor-like framework and also a flexible and pragmatic concurrency toolbox similar to some ML concurrency libraries. The main abstractions are Fibers (execution contexts) and Channels/Ports (messaging conduits and endpoints). From these components, you can build simple to complex concurrent libraries and applications.
Some of the library benefits:
- Tiny library that makes multi-threading simple and easy to reason about
- Thread safe publishing
- Single or multiple subscribers
- Request reply
- UI fibers for worry free UI marshalling
- Batching support
- Scheduling support (Cron, DateTime and TimeSpan based)
Fibrous is great for multi-threading when you don't need extreme low latency or distributed actors but want an easy to reason about and extremely flexible messaging based model. Fibrous is also fast. It's in production use in multiple trading systems, server side and front end.
If you need distributed concurrency, look into Akka.net or Proto.Actor and if you need extreme performance and super low latency, look into Disruptor.net.
Fibers
Fibers are synchronous execution contexts that maintain order of actions. Like Actors, Fibers can manage state without worries of cross threading issues. While a Fiber processes synchronously, your system can consist of multiple Fibers communicating through messaging to provide parallelism to your system.
Fibers subscribe to channels to receive messages which queue actions based on the assigned handler. Fibers have a scheduling API that allows actions to be scheduled in the future as well as repeatedly. You can also directly queue actions onto a Fiber for it to execute.
Fibers are a repository of IDisposable objects and will dispose of all children upon the Fibers disposal. This is used to clean up subscriptions and scheduling for any fiber. This is also useful for dealing with children used in the Fiber's context that implement IDisposable.
There are specialised Fibers for Windows Forms and WPF, which automatically handle invoking actions on the UI/Dispatcher thread. There is a StubFiber, which is used for testing and special cases, and immediately executes actions on the calling thread.
//Representations of the IFiber interface.
//There are many extensions to enable more complex behavior
public interface IFiber : IDisposable
{
void Enqueue(Func<Task> action);
void Enqueue(Action action);
IDisposable Schedule(Func<Task> action, TimeSpan dueTime);
IDisposable Schedule(Func<Task> action, TimeSpan startTime, TimeSpan interval);
IDisposable Schedule(Action action, TimeSpan dueTime);
IDisposable Schedule(Action action, TimeSpan startTime, TimeSpan interval);
void Add(IDisposable toAdd);
void Remove(IDisposable toRemove);
}
//Work is done on the thread pool, but in a sequential fashion
IFiber fiber = new Fiber();
//You can enqueue methods
fiber.Enqueue(SomeParameterlessMethod);
//or lambdas
fiber.Enqueue(() => DoSomeWork(someParam));
//You can schedule when things happen
fiber.Schedule(ScheduledMethod, when);
//and also have them repeat
fiber.Schedule(ScheduledMethod, startWhen, repeatInterval);
Ports and Channels
Ports are the end points for publishing and subscribing to messages.
The port types (ISubscriberPort<T>, IPublisherPort<T>, IRequestPort<TRequest, TReply>, ISnapshotSubscriberPort<T, TSnapshot>, IEventPort and IEventTrigger) allow a variety of behavior around message passing and events.
Channels are the conduit for message passing between Fibers, and allow decoupling of the parts of your system. There are a variety of channel types built into Fibrous: one way channels that notify all subscribers, request/reply, queue channels that give messages to one of multiple subscribers, as well as a state channel that acts like a last value cache.
There is a static EventBus which allows a simpler mechanism for passing messages when only one normal channel per type is needed and an EventHub that allows auto-wiring of handlers.
There are a variety of subscription methods, including filtered, batched, keyed batched and the last message after a time interval.
Examples:
IFiber fiber = new Fiber();
//Create a channel and subscribe to messages
var channel = new Channel<string>();
channel.Subscribe(fiber, s => Console.WriteLine(s.ToUpper()));
//You can also create a channel and subscribe in one line
var channel = fiber.NewChannel<string>(s => Console.WriteLine(s.ToUpper()));
//Publish a message to the channel
channel.Publish("the message");
//EventBus... Global static channel per type (string is only used as an example)
EventBus<string>.Subscribe(fiber, s => Console.WriteLine(s.ToUpper()));
EventBus<string>.Publish("the message");
//Agents make some things even simpler
var agent = new Agent<string>(s => Console.WriteLine(s.ToUpper()));
agent.Publish("the message");
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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. net9.0 is compatible. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Fibrous:
Package | Downloads |
---|---|
Fibrous.WPF
High performace concurrency library for the .Net platform. |
|
Fibrous.Proxy
Automatic fiber based proxy generation |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
6.0.0 | 88 | 12/8/2024 |
5.1.0 | 12,180 | 10/29/2023 |
5.0.0 | 2,757 | 5/27/2021 |
4.1.0 | 9,245 | 8/8/2020 |
4.0.0 | 4,814 | 4/18/2020 |
3.2.0 | 1,618 | 1/9/2020 |
3.1.0 | 690 | 12/18/2019 |
3.0.5 | 584 | 12/2/2019 |
3.0.4 | 975 | 11/21/2019 |
3.0.3-beta | 539 | 11/19/2019 |
3.0.2-beta | 517 | 11/19/2019 |
3.0.1-beta | 521 | 11/17/2019 |
3.0.0-beta | 537 | 11/17/2019 |
2.1.0 | 1,256 | 9/19/2019 |
2.0.0 | 3,102 | 3/4/2018 |
2.0.0-beta | 1,010 | 2/4/2018 |
1.0.8 | 1,262 | 12/19/2015 |
1.0.7 | 1,064 | 12/19/2015 |
1.0.6 | 1,372 | 5/30/2015 |
1.0.1 | 1,567 | 1/5/2013 |
1.0.0 | 1,297 | 12/21/2012 |