UNPKG

1.09 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.PromiseTimeout = PromiseTimeout;
4exports.awaitEventOnce = awaitEventOnce;
5/**
6 * @group Utils
7 */
8function PromiseTimeout(timeout) {
9 return new Promise(resolve => {
10 setTimeout(() => resolve(), timeout);
11 });
12}
13// eslint-disable-next-line @typescript-eslint/ban-types
14function awaitEventOnce(element, event, timeout = 5000) {
15 return new Promise((resolve, reject) => {
16 // eslint-disable-next-line prefer-const
17 let timeoutId;
18 // eslint-disable-next-line @typescript-eslint/no-explicit-any
19 const resolveListener = (...args) => {
20 clearTimeout(timeoutId);
21 resolve(args.length ? (args.length === 1 ? args[0] : args) : undefined);
22 };
23 timeoutId = setTimeout(() => {
24 element.removeListener(event, resolveListener);
25 reject(new Error(`awaitEvent for event ${event} timed out!`));
26 }, timeout);
27 element.once(event, resolveListener);
28 });
29}
30//# sourceMappingURL=promise-utils.js.map
\No newline at end of file