mirror of
https://activitypub.software/TransFem-org/Sharkey.git
synced 2024-12-16 10:11:54 +01:00
23 lines
672 B
TypeScript
23 lines
672 B
TypeScript
/*
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
const promiseRefs: Set<WeakRef<Promise<unknown>>> = new Set();
|
|
|
|
/**
|
|
* This tracks promises that other modules decided not to wait for,
|
|
* and makes sure they are all settled before fully closing down the server.
|
|
*/
|
|
export function trackPromise(promise: Promise<unknown>) {
|
|
if (process.env.NODE_ENV !== 'test') {
|
|
return;
|
|
}
|
|
const ref = new WeakRef(promise);
|
|
promiseRefs.add(ref);
|
|
promise.finally(() => promiseRefs.delete(ref));
|
|
}
|
|
|
|
export async function allSettled(): Promise<void> {
|
|
await Promise.allSettled([...promiseRefs].map(r => r.deref()));
|
|
}
|