utils.js
744 字节
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
/**
* Generic class for handling creation of resources
* for testing
*/
var ResourceFactory = function ResourceFactory () {
this.created = 0
this.destroyed = 0
this.bin = []
}
ResourceFactory.prototype.create = function () {
var id = this.created++
var resource = {
id: id
}
return Promise.resolve(resource)
}
ResourceFactory.prototype.destroy = function (resource) {
this.destroyed++
this.bin.push(resource)
return Promise.resolve()
}
exports.ResourceFactory = ResourceFactory
/**
* drains and terminates the pool
*
* @param {[type]} pool [description]
* @return {[type]} [description]
*/
exports.stopPool = function (pool) {
return pool.drain()
.then(function () {
return pool.clear()
})
}