-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
39 lines (31 loc) · 784 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict';
var Promise = require('bluebird')
class Pipeline {
constructor(handlers) {
if (!handlers)
this.handlers = []
else
this.handlers = handlers
}
use(handler){
this.handlers.push(handler)
return this
}
start(input, output){
if (!output)
output = {}
return new Promise((resolve, reject) => {
var index = 0
var next = function(){
if (index == this.handlers.length)
resolve(output)
else {
let h = this.handlers[index++]
h(input, output, next)
}
}.bind(this)
next()
})
}
}
module.exports = Pipeline