1 line
5.8 KiB
JSON
1 line
5.8 KiB
JSON
{"ast":null,"code":"function limiter(count) {\n var outstanding = 0;\n var jobs = [];\n function remove() {\n outstanding--;\n if (outstanding < count) {\n dequeue();\n }\n }\n function dequeue() {\n var job = jobs.shift();\n semaphore.queue = jobs.length;\n if (job) {\n run(job.fn).then(job.resolve).catch(job.reject);\n }\n }\n function queue(fn) {\n return new Promise(function (resolve, reject) {\n jobs.push({\n fn: fn,\n resolve: resolve,\n reject: reject\n });\n semaphore.queue = jobs.length;\n });\n }\n function run(fn) {\n outstanding++;\n try {\n return Promise.resolve(fn()).then(function (result) {\n remove();\n return result;\n }, function (error) {\n remove();\n throw error;\n });\n } catch (err) {\n remove();\n return Promise.reject(err);\n }\n }\n var semaphore = function (fn) {\n if (outstanding >= count) {\n return queue(fn);\n } else {\n return run(fn);\n }\n };\n return semaphore;\n}\nfunction map(items, mapper) {\n var failed = false;\n var limit = this;\n return Promise.all(items.map(function () {\n var args = arguments;\n return limit(function () {\n if (!failed) {\n return mapper.apply(undefined, args).catch(function (e) {\n failed = true;\n throw e;\n });\n }\n });\n }));\n}\nfunction addExtras(fn) {\n fn.queue = 0;\n fn.map = map;\n return fn;\n}\nmodule.exports = function (count) {\n if (count) {\n return addExtras(limiter(count));\n } else {\n return addExtras(function (fn) {\n return fn();\n });\n }\n};","map":{"version":3,"names":["limiter","count","outstanding","jobs","remove","dequeue","job","shift","semaphore","queue","length","run","fn","then","resolve","catch","reject","Promise","push","result","error","err","map","items","mapper","failed","limit","all","args","arguments","apply","undefined","e","addExtras","module","exports"],"sources":["/Users/shoofle/Projects/the-forest/node_modules/promise-limit/index.js"],"sourcesContent":["function limiter (count) {\n var outstanding = 0\n var jobs = []\n\n function remove () {\n outstanding--\n\n if (outstanding < count) {\n dequeue()\n }\n }\n\n function dequeue () {\n var job = jobs.shift()\n semaphore.queue = jobs.length\n\n if (job) {\n run(job.fn).then(job.resolve).catch(job.reject)\n }\n }\n\n function queue (fn) {\n return new Promise(function (resolve, reject) {\n jobs.push({fn: fn, resolve: resolve, reject: reject})\n semaphore.queue = jobs.length\n })\n }\n\n function run (fn) {\n outstanding++\n try {\n return Promise.resolve(fn()).then(function (result) {\n remove()\n return result\n }, function (error) {\n remove()\n throw error\n })\n } catch (err) {\n remove()\n return Promise.reject(err)\n }\n }\n\n var semaphore = function (fn) {\n if (outstanding >= count) {\n return queue(fn)\n } else {\n return run(fn)\n }\n }\n\n return semaphore\n}\n\nfunction map (items, mapper) {\n var failed = false\n\n var limit = this\n\n return Promise.all(items.map(function () {\n var args = arguments\n return limit(function () {\n if (!failed) {\n return mapper.apply(undefined, args).catch(function (e) {\n failed = true\n throw e\n })\n }\n })\n }))\n}\n\nfunction addExtras (fn) {\n fn.queue = 0\n fn.map = map\n return fn\n}\n\nmodule.exports = function (count) {\n if (count) {\n return addExtras(limiter(count))\n } else {\n return addExtras(function (fn) {\n return fn()\n })\n }\n}\n"],"mappings":"AAAA,SAASA,OAAOA,CAAEC,KAAK,EAAE;EACvB,IAAIC,WAAW,GAAG,CAAC;EACnB,IAAIC,IAAI,GAAG,EAAE;EAEb,SAASC,MAAMA,CAAA,EAAI;IACjBF,WAAW,EAAE;IAEb,IAAIA,WAAW,GAAGD,KAAK,EAAE;MACvBI,OAAO,CAAC,CAAC;IACX;EACF;EAEA,SAASA,OAAOA,CAAA,EAAI;IAClB,IAAIC,GAAG,GAAGH,IAAI,CAACI,KAAK,CAAC,CAAC;IACtBC,SAAS,CAACC,KAAK,GAAGN,IAAI,CAACO,MAAM;IAE7B,IAAIJ,GAAG,EAAE;MACPK,GAAG,CAACL,GAAG,CAACM,EAAE,CAAC,CAACC,IAAI,CAACP,GAAG,CAACQ,OAAO,CAAC,CAACC,KAAK,CAACT,GAAG,CAACU,MAAM,CAAC;IACjD;EACF;EAEA,SAASP,KAAKA,CAAEG,EAAE,EAAE;IAClB,OAAO,IAAIK,OAAO,CAAC,UAAUH,OAAO,EAAEE,MAAM,EAAE;MAC5Cb,IAAI,CAACe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