utils.js
791 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
38
39
40
41
42
"use strict";
const Pool = require("../lib/Pool");
/**
* Generic class for handling creation of resources
* for testing
*/
class ResourceFactory {
constructor() {
this.created = 0;
this.destroyed = 0;
this.bin = [];
}
create() {
return Promise.resolve({ id: this.created++ });
}
validate() {
return Promise.resolve(true);
}
destroy(resource) {
this.destroyed++;
this.bin.push(resource);
return Promise.resolve();
}
}
exports.ResourceFactory = ResourceFactory;
/**
* drains and terminates the pool
*
* @param {Pool} pool [description]
* @return {Promise} [description]
*/
exports.stopPool = function(pool) {
return pool.drain().then(function() {
return pool.clear();
});
};