actor_system 0.7.1 copy "actor_system: ^0.7.1" to clipboard
actor_system: ^0.7.1 copied to clipboard

An implementation of the actor model in the Dart language. An actor processes only one message at a time, even if the processing is asynchronous.

example/main.dart

import 'package:actor_system/actor_system.dart';

// actor factory
Actor actorFactory(Uri path) {
  // some actor state
  int calls = 0;

  // a message handler that handles all messages for that actor
  return (ActorContext context, Object? message) async {
    // count incoming messages
    calls++;

    // just print the received message
    print("actor: ${context.current.path}, message: $message, correlationId: ${context.correlationId}, call: $calls");

    // forward message to the replyTo actor
    await context.replyTo?.send(message, correlationId: context.correlationId);
  };
}

void main() async {
  // create the actor system
  final actorSystem = ActorSystem();

  // create 2 actors
  final actorRef1 = await actorSystem.createActor(actorPath('/test/1'), factory: actorFactory);
  await actorSystem.createActor(actorPath('/test/2'), factory: actorFactory);

  // lookup an actor
  final actorRef2 = await actorSystem.lookupActor(actorPath('/test/2'));

  // send messages to an actor
  await actorRef1.send('message1', correlationId: '1', replyTo: actorRef2);
  await actorRef1.send('message2', correlationId: '2', replyTo: actorRef2);
}
3
likes
0
pub points
0%
popularity

Publisher

verified publisherblimster.net

An implementation of the actor model in the Dart language. An actor processes only one message at a time, even if the processing is asynchronous.

Homepage

License

unknown (license)

Dependencies

logging, metrics

More

Packages that depend on actor_system