Created
November 30, 2015 08:12
-
-
Save ssnau/8f29e620cf7816d50618 to your computer and use it in GitHub Desktop.
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
function m1(next) { | |
console.log('1: start'); | |
next(); | |
console.log("1: end") | |
} | |
function m2(next) { | |
console.log('2: start'); | |
next(); | |
console.log('2: end'); | |
} | |
function m3(next) { | |
console.log('3: start'); | |
next(); | |
console.log('3: end'); | |
} | |
var middleware = compose([m1, m2, m3]); | |
middleware(); | |
function noop(){} | |
function compose(middlewares) { | |
return function middleware() { | |
var stack = middlewares.slice(); | |
function next() { | |
var handler = stack.shift(); | |
if (!handler) return; | |
handler(next); | |
} | |
next(); | |
return next; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment