Created
March 17, 2020 05:33
-
-
Save bpinedah/3d52c4d0c9f93f0ba6db51562fc29e3b to your computer and use it in GitHub Desktop.
Routes article
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @description Create function with middlewares | |
* @param f Middleware functions to execute | |
* @returns {*} | |
* @private | |
*/ | |
const _createPipeline = f => { | |
const signal = { continue: true }; | |
return f.length > 1 ? f.reduce((before, after, idx) => | |
e => before(e , _res(signal)(), _next(idx, f.length)).then(r => { | |
const response = signal.continue ? after(...[...r, _res(signal)(), _next(idx, f.length)]) : r; | |
signal.continue = true; | |
return response; | |
} | |
)) : e => f[0](e, _res(signal)(), _res(signal)().send).then(r => (r)); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment