throw error after 5 seconds if wallet-core didn't reply to a command
This commit is contained in:
parent
2c14a180c1
commit
252382a937
@ -14,8 +14,13 @@
|
|||||||
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { classifyTalerUri, Logger, TalerUriType } from "@gnu-taler/taler-util";
|
import {
|
||||||
import { WalletOperations } from "@gnu-taler/taler-wallet-core";
|
classifyTalerUri,
|
||||||
|
Logger,
|
||||||
|
TalerErrorCode,
|
||||||
|
TalerUriType,
|
||||||
|
} from "@gnu-taler/taler-util";
|
||||||
|
import { TalerError, WalletOperations } from "@gnu-taler/taler-wallet-core";
|
||||||
import { BackgroundOperations } from "../wxApi.js";
|
import { BackgroundOperations } from "../wxApi.js";
|
||||||
import {
|
import {
|
||||||
BackgroundPlatformAPI,
|
BackgroundPlatformAPI,
|
||||||
@ -321,12 +326,15 @@ async function sendMessageToBackground<
|
|||||||
return new Promise<any>((resolve, reject) => {
|
return new Promise<any>((resolve, reject) => {
|
||||||
logger.trace("send operation to the wallet background", message);
|
logger.trace("send operation to the wallet background", message);
|
||||||
let timedout = false;
|
let timedout = false;
|
||||||
setTimeout(() => {
|
const timerId = setTimeout(() => {
|
||||||
timedout = true;
|
timedout = true;
|
||||||
reject("timedout");
|
throw TalerError.fromDetail(TalerErrorCode.GENERIC_TIMEOUT, {});
|
||||||
}, 2000);
|
}, 5 * 1000); //five seconds
|
||||||
chrome.runtime.sendMessage(messageWithId, (backgroundResponse) => {
|
chrome.runtime.sendMessage(messageWithId, (backgroundResponse) => {
|
||||||
if (timedout) return false;
|
if (timedout) {
|
||||||
|
return false; //already rejected
|
||||||
|
}
|
||||||
|
clearTimeout(timerId);
|
||||||
if (chrome.runtime.lastError) {
|
if (chrome.runtime.lastError) {
|
||||||
reject(chrome.runtime.lastError.message);
|
reject(chrome.runtime.lastError.message);
|
||||||
} else {
|
} else {
|
||||||
@ -595,7 +603,7 @@ interface OffscreenCanvasRenderingContext2D
|
|||||||
}
|
}
|
||||||
declare const OffscreenCanvasRenderingContext2D: {
|
declare const OffscreenCanvasRenderingContext2D: {
|
||||||
prototype: OffscreenCanvasRenderingContext2D;
|
prototype: OffscreenCanvasRenderingContext2D;
|
||||||
new (): OffscreenCanvasRenderingContext2D;
|
new(): OffscreenCanvasRenderingContext2D;
|
||||||
};
|
};
|
||||||
|
|
||||||
interface OffscreenCanvas extends EventTarget {
|
interface OffscreenCanvas extends EventTarget {
|
||||||
@ -608,7 +616,7 @@ interface OffscreenCanvas extends EventTarget {
|
|||||||
}
|
}
|
||||||
declare const OffscreenCanvas: {
|
declare const OffscreenCanvas: {
|
||||||
prototype: OffscreenCanvas;
|
prototype: OffscreenCanvas;
|
||||||
new (width: number, height: number): OffscreenCanvas;
|
new(width: number, height: number): OffscreenCanvas;
|
||||||
};
|
};
|
||||||
|
|
||||||
function createCanvas(size: number): OffscreenCanvas {
|
function createCanvas(size: number): OffscreenCanvas {
|
||||||
|
Loading…
Reference in New Issue
Block a user