internal
Internal queue for your public libraries and APIs. This library makes it easy to build asynchronous fluent APIs. You can also think of it as embedded promises.
Some examples of APIs you can build using internal:
Features
- Runs asynchronous functions in order
- Supports namespacing at any depth
- Returns a promise for additional chaining
- API methods can be synchronous, asynchronous, generators or promises
- All methods are yieldable inside co
Usage
building a simple redis client:
var Internal = require('internal')
var client = require('redis')
var internal = Internal({
connect: function (url) {
this.client = client.createClient(url)
},
get: function (key, fn) {
this.client.get(key, fn)
},
set: function (key, value, fn) {
this.client.set(key, value, fn)
}
})
function Redis () {
}
Redis.prototype.connect = function (url) {
return internal().connect(url)
}
var redis = new Redis()
redis
.connect('redis://localhost')
.set('key', 'value')
.get('key')
.then(value => console.log(value))
See test for additional usage examples
Installation
npm install internal
License
MIT, go wild.