UNPKG

async-injection

Version:

A robust lightweight dependency injection library for TypeScript.

40 lines 1.52 kB
import { RELEASE_METADATA_KEY } from './constants.js'; /** * Returns true if the specified object looks like a JavaScript Error object. */ export function isErrorObj(err) { if (!err) return false; if (err instanceof Error) return true; return !!(err && typeof err.message === 'string' && typeof err.stack === 'string'); } /** * Returns true if the specified value is "thenable" (aka a Promise). */ export function isPromise(value) { if (!value) return false; if (value instanceof Promise) return true; return !!(value && typeof value.then === 'function'); } /** * Simple helper function to find the @Release decorated method of an object (if any), and invoke it. * This is primarily an internal method as you probably know the exact method, and should invoke it yourself. * async-injection uses this helper to allow Singletons to clean up any non-garbage-collectable resources they may have allocated. */ export function InvokeReleaseMethod(obj) { var _a, _b; const o = obj; const releaseMethod = Reflect.getMetadata(RELEASE_METADATA_KEY, o.constructor); if (releaseMethod && o.constructor.prototype[releaseMethod] && typeof o.constructor.prototype[releaseMethod] === 'function') { const releaseFn = (_b = (_a = o[releaseMethod]).bind) === null || _b === void 0 ? void 0 : _b.call(_a, o); if (releaseFn) { releaseFn(); return true; } } return false; } //# sourceMappingURL=utils.js.map