BakeryJS
BakeryJS copied to clipboard
Middleware API
This could be used to implement: #39, #25, #44.
- Setup globally, for program
- Wraps each box in a flow
- Receives an instance of box and its metadata, can (re-)call it
Since box can emit unlimited amount of messages, a plain Koa-like middleware won't cut it. We can use generators though and yield to the middleware. The user-level API may look like this:
function myFancyMiddleware (ctx, next) {
// do something before the box is called
for (let message of next()) {
// do something with message
// pass the message up the middleware chain
yield message
}
// do something once the box is done
}
Prototype here https://github.com/jnv/bakeryjs-middlewares-prototype