Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
cressie176 committed Aug 24, 2023
1 parent 3f81636 commit f1188b7
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions lib/Pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,26 @@ module.exports = class Pool extends EventEmitter {
this._initialiseTimeout = validateNumber('initialiseTimeout', options, false, 1);
this._shutdownTimeout = validateNumber('shutdownTimeout', options, false, 1);
this._state = new State({ maxSize: options.maxSize, minSize: options.minSize });

this.initialise = this._initialiseTimeout ? this._initialiseWithTimeout : this._initialiseWithoutTimeout;
}

async initialise() {
async _initialiseWithTimeout() {
this._assertRunning();
return runInContext(async () => {
debug('[%d] Initialising', getContextId());
let resources;
if (this._initialiseTimeout) {
const task = this._createInitialiseTask();
resources = await task.execute();
} else {
const task = { isAborted: () => false };
resources = await this._batchAquire(task);
}
const task = this._createInitialiseTask();
const resources = await task.execute();
resources.forEach((resource) => this.release(resource));
});
}

async _initialiseWithoutTimeout() {
this._assertRunning();
return runInContext(async () => {
debug('[%d] Initialising', getContextId());
const task = { isAborted: () => false };
const resources = await this._batchAquire(task);
resources.forEach((resource) => this.release(resource));
});
}
Expand Down

0 comments on commit f1188b7

Please sign in to comment.