@anyit/actor
TypeScript icon, indicating that this package has built-in type declarations

1.0.11 • Public • Published

Actor-Based System Library

This library provides an implementation of the actor model for handling concurrency. It includes components like Actor, ActorResolver, Environment, and more.

Table of Contents

Key Components

Actor

The foundational piece in the library, representing an individual unit of computation.

  • Properties: address, inbox, listeners, everythingListeners
  • Methods: handleMessage, subscribe, tell, process, emitToListeners

ActorResolver

A component responsible for managing and resolving actor addresses.

  • Methods: getNewAddress, register, resolve

Environment

Represents the context in which actors operate. It associates an actor resolver and a message transmitter.

MessageTransmitter

Abstract class responsible for sending messages to actors.

  • Methods: send

ActorRef

Reference to an actor which allows sending messages.

  • Methods: tell, ask

ActorSystem

The main system for creating, managing, and communicating with actors.

  • Methods: resolve, getRef, create

Installation

Via npm:

npm install @anyit/actor --save

Via yarn:

yarn add @anyit/actor

Peer Dependencies:

Ensure you have the necessary peer dependencies installed:

npm install reflect-metadata @anyit/messaging @anyit/messaging-handling --save

or with yarn:

yarn add reflect-metadata @anyit/messaging @anyit/messaging-handling

Usage

  1. Creating an Actor:
   const actorRef = ActorSystem.create(MyActorClass, { customArg: 'value' });
  1. Subscribing to Messages::
actor.subscribe(new Subscribe({ listener: anotherActorRef, messageTypes: [SomeMessage] }));;
  1. Send a message to an actor:
actorRef.tell(new MyMessage('Hello, World!'));
  1. Asking a message from an actor:
const {response, reason, error} = actorRef.ask(new MyMessage('Hello, World!'));
// response is SuccessMessage or ErrorMessage
// reason is MyMessage
// error is Error if actor responded with ErrorMessage
  1. Resolve an actor by address:
const resolvedActorRef = ActorSystem.resolve('some-actor-address');

Readme

Keywords

none

Package Sidebar

Install

npm i @anyit/actor

Weekly Downloads

1

Version

1.0.11

License

MIT

Unpacked Size

22.9 kB

Total Files

5

Last publish

Collaborators

  • anton.nagornyi