All Projects → nucleartide → Actor.js

nucleartide / Actor.js

Elixir-style actors in JavaScript

Programming Languages

javascript
184084 projects - #8 most used programming language
elixir
2628 projects
flow
126 projects

Projects that are alternatives of or similar to Actor.js

Bastion
Highly-available Distributed Fault-tolerant Runtime
Stars: ✭ 2,333 (+4760.42%)
Mutual labels:  concurrency, actor
Vert.x
Vert.x is a tool-kit for building reactive applications on the JVM
Stars: ✭ 12,544 (+26033.33%)
Mutual labels:  concurrency, event-loop
Akka.net
Port of Akka actors for .NET
Stars: ✭ 4,024 (+8283.33%)
Mutual labels:  concurrency, actor
Sobjectizer
An implementation of Actor, Publish-Subscribe, and CSP models in one rather small C++ framework. With performance, quality, and stability proved by years in the production.
Stars: ✭ 172 (+258.33%)
Mutual labels:  concurrency, actor
nested scheduler
Shard for creating separate groups of fibers in a hierarchical way and to collect results and errors in a structured way.
Stars: ✭ 20 (-58.33%)
Mutual labels:  concurrency, event-loop
cl-gserver
Actor framework featuring actors and agents for easy access to state and asynchronous operations.
Stars: ✭ 121 (+152.08%)
Mutual labels:  concurrency, actor
Actix
Actor framework for Rust.
Stars: ✭ 6,764 (+13991.67%)
Mutual labels:  concurrency, actor
Java Concurrency
Checklist for code reviews
Stars: ✭ 842 (+1654.17%)
Mutual labels:  concurrency
Gmq
基于事件机制的多模块框架,支持动态库,grpc,websocket,mqtt等多种与后端通信组合方式. 模块动态替换,部分加载或者升级.
Stars: ✭ 31 (-35.42%)
Mutual labels:  event-loop
Go Concurrency Test
Test the performance of Go's concurrency structures
Stars: ✭ 24 (-50%)
Mutual labels:  concurrency
Mt
tlock, RWMUTEX, Collab, USM, RSem and other C++ templates for Windows to provide read/write mutex locks, various multithreading tools, collaboration, differential updates and more
Stars: ✭ 18 (-62.5%)
Mutual labels:  concurrency
Bloc
A predictable state management library that helps implement the BLoC design pattern
Stars: ✭ 8,214 (+17012.5%)
Mutual labels:  concurrency
Orleans
Orleans is a cross-platform framework for building distributed applications with .NET
Stars: ✭ 8,131 (+16839.58%)
Mutual labels:  concurrency
Bree
🚥 The best job scheduler for Node.js and JavaScript with cron, dates, ms, later, and human-friendly support. Works in Node v10+ and browsers, uses workers to spawn sandboxed processes, and supports async/await, retries, throttling, concurrency, and graceful shutdown. Simple, fast, and lightweight. Made for @ForwardEmail and @ladjs.
Stars: ✭ 933 (+1843.75%)
Mutual labels:  concurrency
Uvloop
Ultra fast asyncio event loop.
Stars: ✭ 8,246 (+17079.17%)
Mutual labels:  event-loop
May actor
Local Actor library based on may
Stars: ✭ 19 (-60.42%)
Mutual labels:  actor
Three Chat Servers
Example code to go with the talk of the same name and the Ruby Magic concurrency series of blog posts.
Stars: ✭ 46 (-4.17%)
Mutual labels:  concurrency
Eventlet
Concurrent networking library for Python
Stars: ✭ 1,003 (+1989.58%)
Mutual labels:  concurrency
Event Loop
ReactPHP's core reactor event loop that libraries can use for evented I/O.
Stars: ✭ 945 (+1868.75%)
Mutual labels:  event-loop
Pykka
🌀 Pykka makes it easier to build concurrent applications.
Stars: ✭ 944 (+1866.67%)
Mutual labels:  concurrency

actor.js

Elixir-style actors in JavaScript. Spawn "processes", then send and receive messages between them – just like you would in Elixir.

You can think of it as co, but with message passing.


NOTE: Don't use this library. Currently, it doesn't use Web Workers or Node's child_process under the hood (and I lack the motivation to write a Web Workers / child_process implementation), so your code isn't actually run in parallel. I mostly wrote this library as an experiment in Elixir-flavored API design.

You can probably find better Web Workers helper libs on npm.


Example

const pid = spawn(async function() {
  const msg = await this.receive(mail => {
    if (mail === 'hello') return 'world'
  })

  console.log(msg)
})

pid.send('hello')

See the included examples for more use cases.

Install

$ yarn add actorjs

API

spawn(fn | asyncFn, ...args) => PID

Spawn a "process" that will execute the passed-in function.

const pid = spawn(async function(foo, bar) {
  console.log("wee i'm in a process sorta")
}, 'foo', 'bar')

PID#send(msg)

Send a message to a PID.

pid.send(['ok', 'this is a message'])

this.receive(pattern) => Promise

Block until a received message matches the passed-in pattern function.

The pattern function takes an arbitrary message as input, and returns a result based on that message. By default, the pattern function is the identity function.

A result of undefined is not considered to be a match, and thus this.receive() will continue blocking.

const pid = spawn(async function() {
  let v = await this.receive(msg => {
    const [status, value] = msg
    if (status === 'hello') return value
    if (status === 'world') return "won't match"
  })

  v = await this.receive()
})

pid.send(['hello', 'yes this is dog'])
pid.send('anything')

PID#then(value =>), PID#catch(err =>)

The return value of spawn() is a thenable.

spawn(async function() {
  // ...
})
  .then(value => { /* ... */ })
  .catch(console.error)

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].