code optimize

This commit is contained in:
2020-01-16 09:59:19 +08:00
parent d82010686d
commit c78f593c70
8 changed files with 20 additions and 14 deletions

View File

@ -1,6 +1,6 @@
import { Request, Actions } from "../common";
import { getTabByID } from "./actions";
import { logger } from "./common";
import { logger } from "./logger";
/**
* Sending a message to target tab repeatedly until the response is not undefined.
@ -49,7 +49,13 @@ export function sendMessage<T>(
let result: T = r;
if (dataChecker) {
let pms = dataChecker(r, err, count);
let pms: T | Promise<T>;
try {
pms = dataChecker(r, err, count);
} catch (error) {
reject(error);
return;
}
// don't catch if it's not a Promise
if (pms instanceof Promise) {
let checkerError: any;