README
octarine
The actor model for Node.js
Installation
npm install octarine --save
Usage
Start coroutine from function
const co = require('co');
const go = require('octarine');
function fakeCoroutine(result) {
return new Promise((resolve, reject) => {
setTimeout(()=>{
resolve(result);
}, 300);
});
}
co(function* () {
// runs as new process
const result = yield go(fakeCoroutine, ['Terry Pratchett']);
console.log(result); // logs 'Terry Pratchett' after 3s.
}).catch((err) => {
console.log(err.toString());
});
or from own file
main.js
:
/** main.js */
const co = require('co');
const go = require('octarine');
co(function* () {
// runs as new process
const result = yield go("./myCoroutine.js");
console.log(result); // logs 'Terry Pratchett' after 3s.
}).catch((err) => {
console.log(err.toString());
});
myCoroutine.js
:
/** myCoroutine.js */
const ack = require('octarine/ack');
ack('Terry Pratchett');
API
octarine(fn, attr)
Arguments
- fn {
Function
} - function runs as a coroutine - args {
Any[]
} - arguments passed to the function
Returns
- {
Promise
}
Example
const go = require('octarine');
go(() => {
return "hello"; // Or any value, function, promise...
}).then((res) => {
console.log(res); // "hello"
});
octarine(path, attr)
Arguments
- fn {
Function
} - path to coroutine file - args {
Any[]
} - process arguments
Returns
- {
Promise
}
Example
main.js
/** main.js */
const go = require('octarine');
go("myCoroutine.js").then((res) => {
console.log(res); // "hello"
});
myCoroutine.js
/** myCoroutine.js */
const ack = require('octarine/ack');
ack("hello");
ack(result)
Arguments
- result {
Any
}
Example
/** myCoroutine.js */
const ack = require('octarine/ack');
ack("hello");
Changelog
Unstable
]
0.2.0 [+ Run coroutine from file
Unstable
]
0.1.0 [+ First realise
License
Copyright (c) 2016 Alexander Krivoshhekov
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.