55 lines
5.5 KiB
JavaScript
55 lines
5.5 KiB
JavaScript
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||
|
});
|
||
|
};
|
||
|
import Logger from "./Logger";
|
||
|
import { sleep } from "./Utils";
|
||
|
export default class ApplicationComponent {
|
||
|
export(val) {
|
||
|
this.val = val;
|
||
|
}
|
||
|
import() {
|
||
|
if (!this.val)
|
||
|
throw 'Cannot import if nothing was exported.';
|
||
|
return this.val;
|
||
|
}
|
||
|
prepare(name, prepare) {
|
||
|
return __awaiter(this, void 0, void 0, function* () {
|
||
|
let err;
|
||
|
do {
|
||
|
try {
|
||
|
yield prepare();
|
||
|
err = null;
|
||
|
}
|
||
|
catch (e) {
|
||
|
err = e;
|
||
|
Logger.error(err, `${name} failed to prepare; retrying in 5s...`);
|
||
|
yield sleep(5000);
|
||
|
}
|
||
|
} while (err);
|
||
|
Logger.info(`${name} ready!`);
|
||
|
});
|
||
|
}
|
||
|
close(thingName, thing, fn) {
|
||
|
return __awaiter(this, void 0, void 0, function* () {
|
||
|
try {
|
||
|
yield new Promise((resolve, reject) => fn.call(thing, (err) => {
|
||
|
if (err)
|
||
|
reject(err);
|
||
|
else
|
||
|
resolve();
|
||
|
}));
|
||
|
Logger.info(`${thingName} closed.`);
|
||
|
}
|
||
|
catch (e) {
|
||
|
Logger.error(e, `An error occurred while closing the ${thingName}.`);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJ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nQodmFsOiBUKSB7XG4gICAgICAgIHRoaXMudmFsID0gdmFsO1xuICAgIH1cblxuICAgIHB1YmxpYyBpbXBvcnQoKTogVCB7XG4gICAgICAgIGlmICghdGhpcy52YWwpIHRocm93ICdDYW5ub3QgaW1wb3J0IGlmIG5vdGhpbmcgd2FzIGV4cG9ydGVkLic7XG4gICAgICAgIHJldHVybiB0aGlzLnZhbDtcbiAgICB9XG5cbiAgICBwcm90ZWN0ZWQgYXN5bmMgcHJlcGFyZShuYW1lOiBzdHJpbmcsIHByZXBhcmU6ICgpID0+IFByb21pc2U8dm9pZD4pOiBQcm9taXNlPHZvaWQ+IHtcbiAgICAgICAgbGV0IGVycjtcbiAgICAgICAgZG8ge1xuICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICBhd2FpdCBwcmVwYXJlKCk7XG4gICAgICAgICAgICAgICAgZXJyID0gbnVsbDtcbiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcbiAgICAgICAgICAgICAgICBlcnIgPSBlO1xuICAgICAgICAgICAgICAgIExvZ2dlci5lcnJvcihlcnIsIGAke25hbWV9IGZhaWxlZCB0byBwcmVwYXJlOyByZXRyeWluZyBpbiA1cy4uLmApXG4gICAgICAgICAgICAgICAgYXdhaXQgc2xlZXAoNTAwMCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0gd2hpbGUgKGVycik7XG4gICAgICAgIExvZ2dlci5pbmZvKGAke25hbWV9IHJlYWR5IWApO1xuICAgIH1cblxuICAgIHByb3RlY3RlZCBhc3luYyBjbG9zZSh0aGluZ05hbWU6IHN0cmluZywgdGhpbmc6IGFueSwgZm46IEZ1bmN0aW9uKTogUHJvbWlzZTx2b2lkPiB7XG4gICAgICAgIHRyeSB7XG4gICAgICAgICAgICBhd2FpdCBuZXcgUHJvbWlzZSgocmVzb2x2ZSwgcmVqZWN0KSA9PiBmbi5jYWxsKHRoaW5nLCAoZXJyOiBhbnkpID0+IHtcbiAgICAgICAgICAgICAgICBpZiAoZXJyKSByZWplY3QoZXJyKTtcbiAgICAgICAgICAgICAgICBlbHNlIHJlc29sdmUoKTtcbiAgICAgICAgICAgIH0pKTtcblxuICAgICAgICAgICAgTG9nZ2VyLmluZm8oYCR7dGhpbmdOYW1lfSBjbG9zZWQuYCk7XG4gICAgICAgIH0gY2F0Y2ggKGUpIHtcbiAgICAgICAgICAgIExvZ2dlci5lcnJvcihlLCBgQW4gZXJyb3Igb2NjdXJyZWQgd2hpbGUgY2xvc2luZyB0aGUgJHt0aGluZ05hbWV9LmApO1xuICAgICAgICB9XG4gICAgfVxufSJdfQ==
|