1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.withInit = exports.onInit = void 0;
|
4 | const logger = require("../logger");
|
5 | let initCallback = null;
|
6 | let didInit = false;
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | function onInit(callback) {
|
14 | if (initCallback) {
|
15 | logger.warn("Setting onInit callback more than once. Only the most recent callback will be called");
|
16 | }
|
17 | initCallback = callback;
|
18 | didInit = false;
|
19 | }
|
20 | exports.onInit = onInit;
|
21 |
|
22 | function withInit(func) {
|
23 | return async (...args) => {
|
24 | if (!didInit) {
|
25 | if (initCallback) {
|
26 | await initCallback();
|
27 | }
|
28 | didInit = true;
|
29 | }
|
30 |
|
31 |
|
32 |
|
33 | return func(...args);
|
34 | };
|
35 | }
|
36 | exports.withInit = withInit;
|