CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
awaitify.js28 linesDownload Raw Back to internal
1'use strict';2 3Object.defineProperty(exports, "__esModule", {4    value: true5});6exports.default = awaitify;7// conditionally promisify a function.8// only return a promise if a callback is omitted9function awaitify(asyncFn, arity) {10    if (!arity) arity = asyncFn.length;11    if (!arity) throw new Error('arity is undefined');12    function awaitable(...args) {13        if (typeof args[arity - 1] === 'function') {14            return asyncFn.apply(this, args);15        }16 17        return new Promise((resolve, reject) => {18            args[arity - 1] = (err, ...cbArgs) => {19                if (err) return reject(err);20                resolve(cbArgs.length > 1 ? cbArgs : cbArgs[0]);21            };22            asyncFn.apply(this, args);23        });24    }25 26    return awaitable;27}28module.exports = exports.default;
basant307/AI_Governance_Project · CoolFace