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,
|