UNPKG

@beenotung/tslib

Version:
32 lines (31 loc) 710 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isPromise = isPromise; exports.then = then; exports.thenF = thenF; const PromiseString = Promise.resolve().toString(); function isPromise(x) { return String(x) === PromiseString; } function then(x, f, onError) { if (isPromise(x)) { const res = x.then(f); if (onError) { res.catch(onError); } return res; } return f(x); } function thenF(f, q, onError) { try { const x = f(); return then(x, q, onError); } catch (e) { if (typeof onError === 'function') { onError(e); } return Promise.reject(e); } }