UNPKG

util-ex

Version:

Browser-friendly enhanced util fully compatible with standard node.js

23 lines (22 loc) 653 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isAsync = isAsync; /** * Checks if a given value is an asynchronous function or a Promise. * * @param {*} value - The value to check. * @returns {boolean} - Returns true if the value is an asynchronous function or a Promise, otherwise false. */ function isAsync(value) { if (!value) return false; let result = value instanceof Promise; if (!result && typeof value === 'function') { result = value.constructor.name === 'AsyncFunction'; if (!result) { result = value.constructor.name === 'AsyncGeneratorFunction'; } } return result; }