https://github.com/bbqsrc/telekom
https://github.com/bbqsrc/telekom
Last synced: 7 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/bbqsrc/telekom
- Owner: bbqsrc
- License: bsd-2-clause
- Created: 2016-03-04T05:42:42.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-03-05T14:26:16.000Z (almost 10 years ago)
- Last Synced: 2024-12-31T21:11:56.490Z (about 1 year ago)
- Language: JavaScript
- Size: 25.4 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# telekom
An experiment in applying principles of Erlang's OTP (Open Telecom Platform) to
JavaScript for fun and glory.
## Example
`send` returns a `Promise`.
```javascript
// parent.js
const { Process } = require("telekom/process")
const p = new Process("./path/to/child.js")
p.send({ question: "meaning of universe?" }).then(msg => {
console.log(msg) // => prints { answer: 42 }
})
```
```javascript
// child.js
const { ChildProcess } = require("telekom/process")
const proc = new ChildProcess(msg => {
console.log("Got message:", msg)
// Return what you want to reply, if anything
return { answer: 42 }
})
const proc2 = new ChildProcess(function*(msg) {
// You can use generators as well!
const res = yield someYieldable(msg)
return res
})
```
```javascript
/* worker.js */
const { ChildProcess } = require("telekom/process")
// Simply multiple what is received
const proc = new ChildProcess(value => value * 2)
/* poolexample.js */
const { Pool } = require("telekom/pool")
const pool = new Pool("./path/to/worker.js") // Defaults to using number of CPUs
const data = [1, 2, 3, 4]
const res1 = yield pool.map(data) // => [2, 4, 6, 8]
const res2 = yield pool.reduce(data, (cur, next) => {
return cur + next
}, 0) // => 20
```
## License
BSD 2-clause license. See LICENSE.