Package Exports
- runtime
- runtime/lib/hrtime
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (runtime) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Getting started - Documentation - Examples - Implementation status - License
The aim of the project is to provide an easy an non opinionated container to develop Runtime Interfaces being the main focus of the library to abstract async function composition into one function. In addition, and to make it expressive, some features were added:
- path-to-regex mapping
- a small declarative Stack API for each stack
- completion with a callback, always on the 1st argument, that is in charge of passing arguments down to other functions on the same stack. Completion using the return value with async-done that supports completion when returning a stream, promise or an observable.
Samples
simple server using the http module
var http = require('http');
var app = require('runtime').create();
app.set({
onHandleNotFound: function(next, req, res){
res.writeHead(404, {'Content-Type': 'text/plain'});
res.end('404: There is no path \''+req.url+'\' defined yet.');
next();
}
});
app.set('get /', app.stack(index, query, end));
function index(next, req, res){
res.write('Hello there ');
return res;
}
function query(next, req, res){
var name = req.url.match(/\?name=([^&]+)/);
var user = name ? name[1] : '"anonymous"';
res.write(user);
return res;
}
function end(next, req, res){
res.end(); next();
}
function router(req, res){
var method = req.method.toLowerCase();
app.stack(method + ' '+ req.url)(req, res);
}
http.createServer(router).listen(8000, function(){
console.log('http server running on port 8000');
});Getting started
Install runtime using npm
npm install runtimeand then require it into a module
var app = require('runtime').create();
app.set(':handle', function(next){
setTimeout(next, Math.random()*10);
})
app.stack('1 2 3 4 5 6')();
app.stack('one two three four five six', {wait: true})();Browser
At the moment is not tested in browsers but it should work. Use it at your own risk though :). Either a browserify or webpack bundle.js should do the trick.
Documentation
module.exports - Runtime API - Stack API
If you have something to ask, feel free to open an issue or come and chat in gitter with any questions. I wouldn't mind at all.
Examples
There are some use cases you can find at the examples directory.
Implementation status
growing a beard feels goood
status: unstableIt's been a while since the project started and finally is getting there. At the moment, the library needs polishing since it has some rough edges I'm working on. Is tested and usable but I want to fix some stuff I'm not really proud about. In any case, the top level API should not suffer any change.
I'll be using it everywhere so the first user involved here is me.