mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
Catch hook errors in two ways:
- try/catch for catching synchronous errors - Promise.allSettled will allow for rejected promises without fast-failing other promises
This commit is contained in:
parent
99e3ad7690
commit
eb4550d2d5
2 changed files with 18 additions and 4 deletions
|
@ -27,14 +27,21 @@ export function getTypedAnswer(): string | null {
|
|||
return typeans?.value ?? null;
|
||||
}
|
||||
|
||||
function _runHook(arr: Array<Callback>): Promise<void[]> {
|
||||
function _runHook(
|
||||
arr: Array<Callback>
|
||||
): Promise<PromiseSettledResult<void | Promise<void>>[]> {
|
||||
const promises: (Promise<void> | void)[] = [];
|
||||
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
promises.push(arr[i]());
|
||||
try {
|
||||
const result = arr[i]();
|
||||
promises.push(result);
|
||||
} catch (error) {
|
||||
console.log("Hook failed: ", error);
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.all(promises);
|
||||
return Promise.allSettled(promises);
|
||||
}
|
||||
|
||||
let _updatingQueue: Promise<void> = Promise.resolve();
|
||||
|
|
|
@ -3,7 +3,14 @@
|
|||
"compilerOptions": {
|
||||
"target": "es6",
|
||||
"module": "es6",
|
||||
"lib": ["es2017", "es2019.array", "es2018.promise", "dom", "dom.iterable"],
|
||||
"lib": [
|
||||
"es2017",
|
||||
"es2019.array",
|
||||
"es2018.promise",
|
||||
"es2020.promise",
|
||||
"dom",
|
||||
"dom.iterable"
|
||||
],
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"lib/*": ["../bazel-bin/ts/lib/*"],
|
||||
|
|
Loading…
Reference in a new issue