Socket
Socket
Sign inDemoInstall

actor-system

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    actor-system

A proof of concept implementation of actor system in JavaScript


Version published
Maintainers
1
Install size
13.1 kB
Created

Readme

Source

JavaScript Actors

This lib is a proof of concept implementation of actor system in JavaScript.

Install

npm install actor-system

Thanks to @kt3k for providing the name in NPM registry.

How to use

  1. Bootstrap actor system.
import { ActorSystem, MessageDispatcher, ExecutionContext, AnimationFrameExecutor } from 'actor-system';

const executor = new AnimationFrameExecutor();
const context = new ExecutionContext(executor);
const dispatcher = new MessageDispatcher(context);
const system = new ActorSystem(dispatcher);

Or by using default set of tools:

import { ActorSystem } from 'actor-system';

const system = ActorSystem.fromDefaults();
  1. Define message types.
import { Message } from 'actor-system';

class Ping extends Message { }
class Pong extends Message { }
  1. Implement actors.
async function PingActor(system) {
  for await (const message of system.dispatcher) {
    switch (message.subject) {
    case Ping:
      system.dispatcher.dispatch(new Pong());
      break;
    }
  }
}

async function PongActor(system) {
  for await (const message of system.dispatcher) {
    switch (message.subject) {
    case Pong:
      system.dispatcher.dispatch(new Ping());
      break;
    }
  }
}

async function Main(system) {
  system.dispatcher.dispatch(new Ping());
}
  1. Spawn them.
system.spawn(PingActor);
system.spawn(PongActor);
system.spawn(Main);

Articles

Keywords

FAQs

Last updated on 04 Jun 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc