Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Middleware API #47

Open
jnv opened this issue Jan 21, 2019 · 2 comments
Open

Middleware API #47

jnv opened this issue Jan 21, 2019 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@jnv
Copy link
Contributor

jnv commented Jan 21, 2019

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
@jnv jnv added the enhancement New feature or request label Jan 21, 2019
@jnv
Copy link
Contributor Author

jnv commented Jan 21, 2019

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
}

@jnv jnv self-assigned this Jan 21, 2019
@jnv
Copy link
Contributor Author

jnv commented Jan 21, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant