{"version":3,"sources":["jsdelivr-header.js","/npm/@aimwhy/run@0.1.0/dist/run.module.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;ACAA,SAAS,UAAU,GACf,OACI,QAAQ,KACQ,iBAAR,GAAmC,mBAAR,IACd,mBAAb,EAAI,MAA4C,mBAAd,EAAI,KAEtD,CAEA,SAAS,IAAI,EAAI,EAAO,GAAI,EAAS,GACjC,GAAkB,mBAAP,EACP,MAAM,IAAI,MAAM,qCAGG,kBAAZ,IACP,EAAc,EACd,EAAU,MAGd,MAAM,EAAY,EAAG,UAAY,OAAO,YAAY,OAE9C,EAAa,IACf,IAAI,EAAQ,KAWZ,OATI,IACM,cAAe,EAEV,IAAc,EAAG,YACxB,EAAQ,IAAI,MAAM,aAClB,EAAM,QAAS,GAHf,QAAQ,KAAK,8CAOd,CAAC,EAAO,EAAM,EAGnB,EAAW,IACb,IAAI,EAAQ,EAYZ,OAVI,IACM,cAAe,EAEV,IAAc,EAAG,YACxB,EAAQ,IAAI,MAAM,EAAI,SACtB,EAAM,MAAQ,EAAI,MAClB,EAAM,QAAS,GAJf,QAAQ,KAAK,8CAQd,CAAC,EAAO,KAAK,EAGxB,IACI,MAAM,EAAS,EAAG,MAAM,EAAS,GACjC,OAAO,UAAU,GAAU,EAAO,KAAK,EAAW,GAAW,CAAC,KAAM,EACxE,CAAE,MAAO,GACL,MAAO,CAAC,EAAK,KACjB,CACJ,QAES","file":"/npm/@aimwhy/run@0.1.0/dist/run.module.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@aimwhy/run@0.1.0/dist/run.module.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/*!\n * run - v0.1.0\n * @aimwhy/run is licensed under the MIT License.\n * http://www.opensource.org/licenses/mit-license\n * @copyright (C) 2011 - 2022 aimWhy\n */\nfunction isPromise(obj) {\n    return (\n        Boolean(obj) &&\n        (typeof obj === \"object\" || typeof obj === \"function\") &&\n        (typeof obj.then === \"function\" && typeof obj.catch === \"function\")\n    );\n}\n\nfunction run(fn, args = [], context, isCatchRace) {\n    if (typeof fn !== \"function\") {\n        throw new Error(\"first Argument must be a function\");\n    }\n\n    if (typeof context === \"boolean\") {\n        isCatchRace = context;\n        context = null;\n    }\n\n    const timestamp = fn.timestamp = String(performance.now());\n\n    const successFn = (value) => {\n        let error = null;\n\n        if (isCatchRace) {\n            if (!(\"timestamp\" in fn)) {\n                console.warn(\"!important: function reference is changed\");\n            } else if (timestamp !== fn.timestamp) {\n                error = new Error(\"RaceError\");\n                error.isRace = true;\n            }\n        }\n\n        return [error, value];\n    };\n\n    const errorFn = (err) => {\n        let error = err;\n\n        if (isCatchRace) {\n            if (!(\"timestamp\" in fn)) {\n                console.warn(\"!important: function reference is changed\");\n            } else if (timestamp !== fn.timestamp) {\n                error = new Error(err.message);\n                error.stack = err.stack;\n                error.isRace = true;\n            }\n        }\n\n        return [error, null];\n    };\n\n    try {\n        const result = fn.apply(context, args);\n        return isPromise(result) ? result.then(successFn, errorFn) : [null, result];\n    } catch (err) {\n        return [err, null];\n    }\n}\n\nexport { run };\n"]}