simplify promise

This commit is contained in:
siikamiika 2020-04-04 17:02:54 +03:00
parent 123e725049
commit 867902523f

View File

@ -318,13 +318,6 @@ const yomichan = (() => {
}
getTemporaryListenerResult(eventHandler, userCallback, timeout=null) {
let resolve;
let reject;
const listenerPromise = new Promise((_resolve, _reject) => {
resolve = _resolve;
reject = _reject;
});
if (
typeof eventHandler.addListener === 'undefined' ||
typeof eventHandler.removeListener === 'undefined'
@ -332,6 +325,7 @@ const yomichan = (() => {
throw new Error('Event handler type not supported');
}
return new Promise((resolve, reject) => {
const runtimeMessageCallback = ({action, params}, sender, sendResponse) => {
let timeoutId = null;
if (timeout !== null) {
@ -356,8 +350,7 @@ const yomichan = (() => {
};
eventHandler.addListener(runtimeMessageCallback);
return listenerPromise;
});
}
// Private