All Projects → renatoathaydes → actors

renatoathaydes / actors

Licence: BSD-2-Clause license
Actor Model library for Dart.

Programming Languages

dart
5743 projects

Projects that are alternatives of or similar to actors

traffic
Massively real-time traffic streaming application
Stars: ✭ 25 (-37.5%)
Mutual labels:  actor-model, concurrency
Akka.net
Port of Akka actors for .NET
Stars: ✭ 4,024 (+9960%)
Mutual labels:  actor-model, concurrency
transit
Massively real-time city transit streaming application
Stars: ✭ 20 (-50%)
Mutual labels:  actor-model, concurrency
ComposableAsync
Create, compose and inject asynchronous behaviors in .Net Framework and .Net Core.
Stars: ✭ 28 (-30%)
Mutual labels:  actor-model, concurrency
Pykka
🌀 Pykka makes it easier to build concurrent applications.
Stars: ✭ 944 (+2260%)
Mutual labels:  actor-model, concurrency
theater
Actor framework for Dart. This package makes it easier to work with isolates, create clusters of isolates.
Stars: ✭ 29 (-27.5%)
Mutual labels:  actor-model, concurrency
Akka
Build highly concurrent, distributed, and resilient message-driven applications on the JVM
Stars: ✭ 11,938 (+29745%)
Mutual labels:  actor-model, concurrency
Cloudi
A Cloud at the lowest level!
Stars: ✭ 352 (+780%)
Mutual labels:  actor-model, concurrency
Thespian
Python Actor concurrency library
Stars: ✭ 220 (+450%)
Mutual labels:  actor-model, concurrency
Actix
Actor framework for Rust.
Stars: ✭ 6,764 (+16810%)
Mutual labels:  actor-model, concurrency
rockgo
A developing game server framework,based on Entity Component System(ECS).
Stars: ✭ 617 (+1442.5%)
Mutual labels:  actor-model, concurrency
So 5 5
SObjectizer: it's all about in-process message dispatching!
Stars: ✭ 87 (+117.5%)
Mutual labels:  actor-model, concurrency
Actors.jl
Concurrent computing in Julia based on the Actor Model
Stars: ✭ 95 (+137.5%)
Mutual labels:  actor-model, concurrency
Sobjectizer
An implementation of Actor, Publish-Subscribe, and CSP models in one rather small C++ framework. With performance, quality, and stability proved by years in the production.
Stars: ✭ 172 (+330%)
Mutual labels:  actor-model, concurrency
Rockgo
A developing game server framework,based on Entity Component System(ECS).
Stars: ✭ 532 (+1230%)
Mutual labels:  actor-model, concurrency
Orleans
Orleans is a cross-platform framework for building distributed applications with .NET
Stars: ✭ 8,131 (+20227.5%)
Mutual labels:  actor-model, concurrency
Chymyst Core
Declarative concurrency in Scala - The implementation of the chemical machine
Stars: ✭ 142 (+255%)
Mutual labels:  actor-model, concurrency
Xian
reactive风格的微服务框架
Stars: ✭ 196 (+390%)
Mutual labels:  actor-model
Coerce Rs
Coerce - an asynchronous (async/await) Actor runtime and cluster framework for Rust
Stars: ✭ 231 (+477.5%)
Mutual labels:  actor-model
Lam
🚀 a lightweight, universal actor-model vm for writing scalable and reliable applications that run natively and on WebAssembly
Stars: ✭ 176 (+340%)
Mutual labels:  actor-model

actors

Actors CI pub package

actors is a library that enables the use of the Actors Model in Dart.

It is a thin wrapper around Dart's Isolate (on Flutter and Dart VM) and Web Workers (on the Web - TODO) that makes them much easier to use.

Actor

To start an Actor is very easy. You simply create a Handler implementing the logic to handle messages within the Actor's Isolate, then create an Actor using it:

class Accumulator with Handler<int, int> {
  int _value;
  
  Accumulator([int initialValue = 0]): _value = initialValue;
  
  int handle(int n) => _value += n;
}

main() async {
  final actor = Actor(Accumulator(6));
  print(await actor.send(5)); // 11
  await actor.close();
}

If your actor does not maintain internal state, it can also be created from a function, or even a lambda:

int two(int n) => n * 2;

main() async {
  final actor = Actor.of(two);
  print(await actor.send(5)); // 10
  await actor.close();
}

As you can see, an Actor can send a message back to the caller asynchronously.

They can also send more than one message by returning a Stream:

// A Handler that returns a Stream must use a StreamActor, not an Actor.
class StreamGenerator with Handler<int, Stream<int>> {
  @override
  Stream<int> handle(int message) {
    return Stream.fromIterable(Iterable.generate(message, (i) => i));
  }
}

main() async {
  // Create an StreamActor from a Handler that returns Stream.
  final actor = StreamActor(StreamGenerator());
  final stream = actor.send(2);
  await for (final item in stream) {
    print(item); // 0, 1
  }
  await actor.close();
}

ActorGroup

ActorGroup allows several Actor instances to be grouped together, all based on the same Handler implementation, but executed according to one of the available strategies:

  • RoundRobin - send message to a single Actor, alternating which member of the group receives the message.
  • MultiHandler - send message to m Actors, wait for at least n successful answers.

RoundRobing is appropriate for cases where messages are CPU intensive to handle and there may be many of them.

MultiHandler is a way to achieve high reliability by duplicating effort, as not all Actors in the group may be healthy at all times. Having a few "backups" doing the same work on each message may be a good idea in case one or more of the expected receivers are likely to fail, as the system will still continue to work without issues as long as n actors remain healthy... Also, by sending the same message to several actors, the message might be received in different locations, making it much harder for it to be lost.

// create a group of 4 actors
final group = ActorGroup(Two(), size: 4);
print(await group.send(5)); // 10
group.close();

Messenger

The Messenger mixin is implemented by Actor, ActorGroup, and also LocalMessenger, which runs its Handler in the local Isolate.

Messenger<int, int> messenger;

// a Messenger can be local
messenger = LocalMessenger(Two());
print(await messenger.send(2)); // 4

// or it can be an Actor
messenger = Actor(Two());
print(await messenger.send(3)); // 6
messenger.close();

// or an ActorGroup
messenger = ActorGroup(Two(), size: 2);
print(await messenger.send(4)); // 8
print(await messenger.send(5)); // 10
messenger.close();

This makes it possible to write code that works the same whether the message is handled locally or in another Isolate.

More examples

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].