Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alexeyraspopov/actor-system
Build robust and resilient message-driven systems
https://github.com/alexeyraspopov/actor-system
actor-system actors event-driven execution-context javascript message-dispatcher
Last synced: about 1 month ago
JSON representation
Build robust and resilient message-driven systems
- Host: GitHub
- URL: https://github.com/alexeyraspopov/actor-system
- Owner: alexeyraspopov
- License: mit
- Created: 2017-03-19T21:53:12.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-06-05T15:06:15.000Z (over 7 years ago)
- Last Synced: 2024-12-01T03:33:54.488Z (about 1 month ago)
- Topics: actor-system, actors, event-driven, execution-context, javascript, message-dispatcher
- Language: JavaScript
- Homepage:
- Size: 56.6 KB
- Stars: 8
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# JavaScript Actors
This lib is a proof of concept implementation of actor system in JavaScript.
## Install
npm install actor-system
Thanks to [@kt3k](https://github.com/kt3k) for providing the name in NPM registry.
## How to use
1. Bootstrap actor system.
```javascript
import { ActorSystem, MessageDispatcher, ExecutionContext, AnimationFrameExecutor } from 'actor-system';const executor = new AnimationFrameExecutor(60);
const context = new ExecutionContext(executor);
const dispatcher = new MessageDispatcher(context);
const system = new ActorSystem(dispatcher);
```Or by using default set of tools:
```javascript
import { ActorSystem } from 'actor-system';const system = ActorSystem.fromDefaults();
```2. Define message types.
```javascript
import { Message } from 'actor-system';class Ping extends Message { }
class Pong extends Message { }
```3. Implement actors.
```javascript
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());
}
```4. Spawn them.
```javascript
system.spawn(PingActor);
system.spawn(PongActor);
system.spawn(Main);
```## Articles
* [Tasks, microtasks, queues and schedules — Jake Archibald](https://jakearchibald.com/2015/tasks-microtasks-queues-and-schedules/)