1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.PromiseTimeout = PromiseTimeout;
|
4 | exports.awaitEventOnce = awaitEventOnce;
|
5 |
|
6 |
|
7 |
|
8 | function PromiseTimeout(timeout) {
|
9 | return new Promise(resolve => {
|
10 | setTimeout(() => resolve(), timeout);
|
11 | });
|
12 | }
|
13 |
|
14 | function awaitEventOnce(element, event, timeout = 5000) {
|
15 | return new Promise((resolve, reject) => {
|
16 |
|
17 | let timeoutId;
|
18 |
|
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 |
|
\ | No newline at end of file |