UNPKG

mongoose-transaction-decorator

Version:
41 lines (40 loc) 1.5 kB
"use strict"; 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()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ALS = void 0; const async_hooks_1 = require("async_hooks"); class ALS { constructor() { this.asyncLocalStorage = new async_hooks_1.AsyncLocalStorage(); return ALS.instance; } run(fn) { return __awaiter(this, void 0, void 0, function* () { return yield this.asyncLocalStorage.run(new Map(), fn); }); } exit() { this.asyncLocalStorage.exit(() => { return; }); } store() { return this.asyncLocalStorage.getStore(); } set(key, value) { this.store().set(key, value); } get(key) { return this.store().get(key); } } exports.ALS = ALS; ALS.instance = new ALS();