Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

actor-system

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

actor-system

A proof of concept implementation of actor system in JavaScript

  • 2.0.0-alpha.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
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

Package last updated on 04 Jun 2017

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc