-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathpool.js
More file actions
33 lines (30 loc) · 1.03 KB
/
pool.js
File metadata and controls
33 lines (30 loc) · 1.03 KB
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
/* obj pool to manage concurrency */
try { var pool = require('generic-pool').Pool; } catch (e) {}
module.exports.create_pool = function(size) {
if (!pool) {
throw new Error('map pool requires generic-pool to be installed:\nnpm install generic-pool');
}
return {
max: size || 5,
pools: {},
acquire: function(id, options, callback) {
if (!this.pools[id]) {
var that = this;
this.pools[id] = pool({
name: id,
create: options.create,
destroy: options.destroy,
max: that.max,
idleTimeoutMillis: options.idleTimeoutMillis || 5000,
log: false
//reapIntervalMillis
//priorityRange
});
}
this.pools[id].acquire(callback, options.priority);
},
release: function(id, obj) {
if (this.pools[id]) this.pools[id].release(obj);
}
};
};