MCPcopy Create free account
hub / github.com/coopernurse/node-pool / constructor

Method constructor

lib/PoolOptions.js:51–106  ·  view source on GitHub ↗

* @param {Object} opts * configuration for the pool * @param {Number} [opts.max=null] * Maximum number of items that can exist at the same time. Default: 1. * Any further acquire requests will be pushed to the waiting list. * @param {Number} [opts.min=null] * Minimum numbe

(opts)

Source from the content-addressed store, hash-verified

49 * What promise implementation should the pool use, defaults to native promises.
50 */
51 constructor(opts) {
52 const poolDefaults = new PoolDefaults();
53
54 opts = opts || {};
55
56 this.fifo = typeof opts.fifo === "boolean" ? opts.fifo : poolDefaults.fifo;
57 this.priorityRange = opts.priorityRange || poolDefaults.priorityRange;
58
59 this.testOnBorrow =
60 typeof opts.testOnBorrow === "boolean"
61 ? opts.testOnBorrow
62 : poolDefaults.testOnBorrow;
63 this.testOnReturn =
64 typeof opts.testOnReturn === "boolean"
65 ? opts.testOnReturn
66 : poolDefaults.testOnReturn;
67
68 this.autostart =
69 typeof opts.autostart === "boolean"
70 ? opts.autostart
71 : poolDefaults.autostart;
72
73 if (opts.acquireTimeoutMillis) {
74 // @ts-ignore
75 this.acquireTimeoutMillis = parseInt(opts.acquireTimeoutMillis, 10);
76 }
77
78 if (opts.destroyTimeoutMillis) {
79 // @ts-ignore
80 this.destroyTimeoutMillis = parseInt(opts.destroyTimeoutMillis, 10);
81 }
82
83 if (opts.maxWaitingClients !== undefined) {
84 // @ts-ignore
85 this.maxWaitingClients = parseInt(opts.maxWaitingClients, 10);
86 }
87
88 // @ts-ignore
89 this.max = parseInt(opts.max, 10);
90 // @ts-ignore
91 this.min = parseInt(opts.min, 10);
92
93 this.max = Math.max(isNaN(this.max) ? 1 : this.max, 1);
94 this.min = Math.min(isNaN(this.min) ? 0 : this.min, this.max);
95
96 this.evictionRunIntervalMillis =
97 opts.evictionRunIntervalMillis || poolDefaults.evictionRunIntervalMillis;
98 this.numTestsPerEvictionRun =
99 opts.numTestsPerEvictionRun || poolDefaults.numTestsPerEvictionRun;
100 this.softIdleTimeoutMillis =
101 opts.softIdleTimeoutMillis || poolDefaults.softIdleTimeoutMillis;
102 this.idleTimeoutMillis =
103 opts.idleTimeoutMillis || poolDefaults.idleTimeoutMillis;
104
105 this.Promise = opts.Promise != null ? opts.Promise : poolDefaults.Promise;
106 }
107}
108

Callers

nothing calls this directly

Calls 2

maxMethod · 0.80
minMethod · 0.80

Tested by

no test coverage detected