Skip to content

Commit

Permalink
refactor(MongoMemoryReplSet): _waitForPrimary: remove value "timeoutP…
Browse files Browse the repository at this point in the history
…romise"

- remove value "_waitForPrimary" because it is only used once
  • Loading branch information
hasezoey committed Oct 12, 2020
1 parent d0d62e2 commit 18b9a58
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions packages/mongodb-memory-server-core/src/MongoMemoryReplSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,11 +456,6 @@ export class MongoMemoryReplSet extends EventEmitter {
*/
protected async _waitForPrimary(timeout: number = 30000): Promise<void> {
let timeoutId: NodeJS.Timeout | undefined;
const timeoutPromise = new Promise((resolve, reject) => {
timeoutId = setTimeout(() => {
reject('Timed out in ' + timeout + 'ms. When waiting for primary.');
}, timeout);
});

await Promise.race([
...this.servers.map(
Expand All @@ -473,7 +468,11 @@ export class MongoMemoryReplSet extends EventEmitter {
instanceInfo.instance.once(MongoInstanceEvents.instancePrimary, res);
})
),
timeoutPromise,
new Promise((res, rej) => {
timeoutId = setTimeout(() => {
rej(`Timed out after ${timeout}ms while waiting for an Primary`);
}, timeout);
}),
]);

if (!isNullOrUndefined(timeoutId)) {
Expand Down

0 comments on commit 18b9a58

Please sign in to comment.