forked from coopernurse/node-pool
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
37 lines (33 loc) · 752 Bytes
/
utils.js
File metadata and controls
37 lines (33 loc) · 752 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() {
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();
});
};