UNPKG

nats-micro

Version:

NATS micro compatible extra-lightweight microservice library

35 lines 1.67 kB
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 { ThreadContextKey, threadContext } from './threadContext.js'; import { ResponseImpl } from '../response.js'; export function callHandler(handler, data, subject, headers, handlerInfo) { return __awaiter(this, void 0, void 0, function* () { const req = { data, subject, headers, handler: handlerInfo, get context() { var _a; return (_a = threadContext.getStore()) === null || _a === void 0 ? void 0 : _a.get(ThreadContextKey.context); }, set context(ctx) { const store = threadContext.getStore(); if (!store) throw new Error('Thread context is not available'); store.set(ThreadContextKey.context, ctx); }, }; const res = new ResponseImpl(); yield handler(req, res); return res.closeWaiter; }); } //# sourceMappingURL=callHandler.js.map