utils.js
718 Bytes
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
/**
* 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 (callback) {
var resource = {
id: this.created++
}
setTimeout(function () {
callback(resource)
}, 1)
}
ResourceFactory.prototype.destroy = function (resource) {
this.destroyed++
this.bin.push(resource)
}
exports.ResourceFactory = ResourceFactory
/**
* drains and terminates the pool
*
* @param {[type]} pool [description]
* @return {[type]} [description]
*/
exports.stopPool = function (pool) {
pool.drain(function () {
pool.destroyAllNow()
})
}