index.js 520 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /**
  2. * Expose compositor.
  3. */
  4. module.exports = compose;
  5. /**
  6. * Compose `middleware` returning
  7. * a fully valid middleware comprised
  8. * of all those which are passed.
  9. *
  10. * @param {Array} middleware
  11. * @return {Function}
  12. * @api public
  13. */
  14. function compose(middleware){
  15. return function *(next){
  16. if (!next) next = noop();
  17. var i = middleware.length;
  18. while (i--) {
  19. next = middleware[i].call(this, next);
  20. }
  21. return yield *next;
  22. }
  23. }
  24. /**
  25. * Noop.
  26. *
  27. * @api private
  28. */
  29. function *noop(){}