UNPKG

es-promise-ext

Version:

Native promise extensions for javascript and typescript.

24 lines (23 loc) 664 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = then; /** * Start promise with a function, which Promise.resolve() does not support. * * @param {T} value * - a value - which would be equivient to Promise.resolve(value) * - a function which will be called and pass the result in promise * * @return {Promise<T>} * A value within a promise * * @example * promiseThen(3) // return 3 in a promise * promiseThen(()=>3) // return 3 in a promise */ function then(value) { if (typeof value === 'function') return Promise.resolve().then(value); else return Promise.resolve(value); }