https://github.com/chatopera/microloom
https://github.com/chatopera/microloom
async compose nodejs
Last synced: 29 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/chatopera/microloom
- Owner: chatopera
- Created: 2016-10-04T10:12:13.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-04-13T02:57:10.000Z (about 9 years ago)
- Last Synced: 2025-03-16T15:05:37.507Z (over 1 year ago)
- Topics: async, compose, nodejs
- Language: JavaScript
- Size: 31.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# Microloom
**Microloom** requires node v7.6.0 or higher for ES2015 and async function support.
## Install
```
npm install microloom --save
```
## Usage
Check out [Example](https://github.com/Samurais/microloom/tree/master/test/test.js).
```
// simulate a request.
function wait(ms) {
return new Promise((resolve) => setTimeout(resolve, ms || 1))
}
let app = require('microloom');
app.use(async function (ctx, next) {
ctx.arr.push(1)
await next()
// process requests with Promise, Generator, Async or any object.
await wait(1)
ctx.arr.push(4)
return ctx;
});
app.use(async function (ctx, next) {
ctx.arr.push(2)
await next()
ctx.arr.push(3)
});
app.handle({ /* Inject ctx value */
arr: [0]
}).then(function (result) {
console.log(result);
// { arr: [ 0, 1, 2, 3, 4 ] }
}).catch(function (e) {
console.error(e)
});
```
## Contribution
```
git clone git@github.com:Samurais/microloom.git
cd microloom
npm install
ava
```
## License
MIT