Ensure that waitForAll functions catch and log thrown errors
This commit is contained in:
parent
45fcf827dd
commit
9e54f55c22
6 changed files with 36 additions and 5 deletions
|
@ -1693,7 +1693,7 @@ async function requestShutdown() {
|
||||||
}
|
}
|
||||||
|
|
||||||
getLogger().info('requestShutdown: Requesting close of mainWindow...');
|
getLogger().info('requestShutdown: Requesting close of mainWindow...');
|
||||||
const request = new Promise<void>((resolveFn, reject) => {
|
const request = new Promise<void>(resolveFn => {
|
||||||
let timeout: NodeJS.Timeout | undefined;
|
let timeout: NodeJS.Timeout | undefined;
|
||||||
|
|
||||||
if (!mainWindow) {
|
if (!mainWindow) {
|
||||||
|
@ -1705,7 +1705,10 @@ async function requestShutdown() {
|
||||||
getLogger().info('requestShutdown: Response received');
|
getLogger().info('requestShutdown: Response received');
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return reject(error);
|
getLogger().error(
|
||||||
|
'requestShutdown: got error, still shutting down.',
|
||||||
|
error
|
||||||
|
);
|
||||||
}
|
}
|
||||||
clearTimeoutIfNecessary(timeout);
|
clearTimeoutIfNecessary(timeout);
|
||||||
|
|
||||||
|
|
|
@ -648,6 +648,7 @@ export async function startApp(): Promise<void> {
|
||||||
server !== undefined,
|
server !== undefined,
|
||||||
'WebAPI should be initialized together with MessageReceiver'
|
'WebAPI should be initialized together with MessageReceiver'
|
||||||
);
|
);
|
||||||
|
log.info('background/shutdown: shutting down messageReceiver');
|
||||||
server.unregisterRequestHandler(messageReceiver);
|
server.unregisterRequestHandler(messageReceiver);
|
||||||
messageReceiver.stopProcessing();
|
messageReceiver.stopProcessing();
|
||||||
await window.waitForAllBatchers();
|
await window.waitForAllBatchers();
|
||||||
|
|
|
@ -673,6 +673,8 @@ function keysFromBytes(keys: Array<string>, data: any) {
|
||||||
// Top-level calls
|
// Top-level calls
|
||||||
|
|
||||||
async function shutdown() {
|
async function shutdown() {
|
||||||
|
log.info('Client.shutdown');
|
||||||
|
|
||||||
// Stop accepting new SQL jobs, flush outstanding queue
|
// Stop accepting new SQL jobs, flush outstanding queue
|
||||||
await _shutdown();
|
await _shutdown();
|
||||||
|
|
||||||
|
|
|
@ -352,6 +352,7 @@ export default class MessageReceiver
|
||||||
}
|
}
|
||||||
|
|
||||||
public stopProcessing(): void {
|
public stopProcessing(): void {
|
||||||
|
log.info('MessageReceiver.stopProcessing');
|
||||||
this.stoppingProcessing = true;
|
this.stoppingProcessing = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import PQueue from 'p-queue';
|
||||||
|
|
||||||
import { sleep } from './sleep';
|
import { sleep } from './sleep';
|
||||||
import * as log from '../logging/log';
|
import * as log from '../logging/log';
|
||||||
|
import * as Errors from '../types/errors';
|
||||||
import { clearTimeoutIfNecessary } from './clearTimeoutIfNecessary';
|
import { clearTimeoutIfNecessary } from './clearTimeoutIfNecessary';
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
@ -20,7 +21,15 @@ declare global {
|
||||||
window.batchers = [];
|
window.batchers = [];
|
||||||
|
|
||||||
window.waitForAllBatchers = async () => {
|
window.waitForAllBatchers = async () => {
|
||||||
|
log.info('batcher#waitForAllBatchers');
|
||||||
|
try {
|
||||||
await Promise.all(window.batchers.map(item => item.flushAndWait()));
|
await Promise.all(window.batchers.map(item => item.flushAndWait()));
|
||||||
|
} catch (error) {
|
||||||
|
log.error(
|
||||||
|
'waitForAllBatchers: error flushing all',
|
||||||
|
Errors.toLogFormat(error)
|
||||||
|
);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export type BatcherOptionsType<ItemType> = {
|
export type BatcherOptionsType<ItemType> = {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import PQueue from 'p-queue';
|
||||||
|
|
||||||
import { sleep } from './sleep';
|
import { sleep } from './sleep';
|
||||||
import * as log from '../logging/log';
|
import * as log from '../logging/log';
|
||||||
|
import * as Errors from '../types/errors';
|
||||||
import { clearTimeoutIfNecessary } from './clearTimeoutIfNecessary';
|
import { clearTimeoutIfNecessary } from './clearTimeoutIfNecessary';
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
@ -22,12 +23,26 @@ window.waitBatchers = [];
|
||||||
|
|
||||||
window.flushAllWaitBatchers = async () => {
|
window.flushAllWaitBatchers = async () => {
|
||||||
log.info('waitBatcher#flushAllWaitBatchers');
|
log.info('waitBatcher#flushAllWaitBatchers');
|
||||||
|
try {
|
||||||
await Promise.all(window.waitBatchers.map(item => item.flushAndWait()));
|
await Promise.all(window.waitBatchers.map(item => item.flushAndWait()));
|
||||||
|
} catch (error) {
|
||||||
|
log.error(
|
||||||
|
'flushAllWaitBatchers: Error flushing all',
|
||||||
|
Errors.toLogFormat(error)
|
||||||
|
);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
window.waitForAllWaitBatchers = async () => {
|
window.waitForAllWaitBatchers = async () => {
|
||||||
log.info('waitBatcher#waitForAllWaitBatchers');
|
log.info('waitBatcher#waitForAllWaitBatchers');
|
||||||
|
try {
|
||||||
await Promise.all(window.waitBatchers.map(item => item.onIdle()));
|
await Promise.all(window.waitBatchers.map(item => item.onIdle()));
|
||||||
|
} catch (error) {
|
||||||
|
log.error(
|
||||||
|
'waitForAllWaitBatchers: Error waiting for all',
|
||||||
|
Errors.toLogFormat(error)
|
||||||
|
);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
type ItemHolderType<ItemType> = {
|
type ItemHolderType<ItemType> = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue