New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@feng3d/task

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@feng3d/task - npm Package Compare versions

Comparing version 0.8.0 to 0.8.1

dist/.nojekyll

119

dist/index.umd.js

@@ -1,2 +0,119 @@

(function(r,i){typeof exports=="object"&&typeof module<"u"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(r=typeof globalThis<"u"?globalThis:r||self,i(r.feng3d={}))})(this,function(r){"use strict";class i{parallel(s){return l=>{if(s.length===0){l();return}let t=0;s.forEach(o=>{let e=0;o(()=>{e++,e===1?(t++,t===s.length&&l()):console.warn(`${o.name?`函数${o.name}`:"匿名函数"} 多次调用回调函数,当前次数 ${e}`)})})}}series(s){return l=>{if(s.length===0){l();return}let t=0;const o=()=>{const e=s[t];let n=0;e(()=>{n++,n===1?(t++,t<s.length?o():l&&l()):console.warn(`${e.name?`函数${e.name}`:"匿名函数"} 多次调用回调函数,当前次数 ${n}`)})};o()}}parallelResults(s,a,l){const t=new Map,o=s.map(e=>n=>{a(e,u=>{t.set(e,u),n()})});this.parallel(o)(()=>{const e=s.map(n=>t.get(n));t.clear(),l(e)})}seriesResults(s,a,l){const t=new Map,o=s.map(e=>n=>{a(e,u=>{t.set(e,u),n()})});this.series(o)(()=>{const e=s.map(n=>t.get(n));t.clear(),l(e)})}}const c=new i;r.task=c,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
(function(global, factory) {
typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.feng3d = {}));
})(this, function(exports2) {
"use strict";
class Task {
/**
* 并联多个异步函数为一个函数
*
* 这些异步函数同时执行
*
* @param fns 一组异步函数
*/
parallel(fns) {
const result = (callback) => {
if (fns.length === 0) {
callback();
return;
}
let index = 0;
fns.forEach((fn) => {
let callbackNum = 0;
fn(() => {
callbackNum++;
if (callbackNum === 1) {
index++;
if (index === fns.length) {
callback();
}
} else {
console.warn(`${fn.name ? `函数${fn.name}` : "匿名函数"} 多次调用回调函数,当前次数 ${callbackNum}`);
}
});
});
};
return result;
}
/**
* 串联多个异步函数为一个函数
*
* 这些异步函数按顺序依次执行,等待前一个异步函数执行完调用回调后才执行下一个异步函数。
*
* @param fns 一组异步函数
*/
series(fns) {
const result = (callback) => {
if (fns.length === 0) {
callback();
return;
}
let index = 0;
const next = () => {
const fn = fns[index];
let callbackNum = 0;
fn(() => {
callbackNum++;
if (callbackNum === 1) {
index++;
if (index < fns.length) {
next();
} else {
callback && callback();
}
} else {
console.warn(`${fn.name ? `函数${fn.name}` : "匿名函数"} 多次调用回调函数,当前次数 ${callbackNum}`);
}
});
};
next();
};
return result;
}
/**
* 创建一组并行同类任务,例如同时加载一组资源,并在回调中返回结果数组
*
* @param ps 一组参数
* @param fn 单一任务函数
* @param done 完成回调
*/
parallelResults(ps, fn, done) {
const map = /* @__PURE__ */ new Map();
const fns = ps.map((p) => (callback) => {
fn(p, (r) => {
map.set(p, r);
callback();
});
});
this.parallel(fns)(() => {
const results = ps.map((p) => map.get(p));
map.clear();
done(results);
});
}
/**
* 创建一组串联同类任务,例如排序加载一组资源
*
* @param ps 一组参数
* @param fn 单一任务函数
* @param done 完成回调
*/
seriesResults(ps, fn, done) {
const map = /* @__PURE__ */ new Map();
const fns = ps.map((p) => (callback) => {
fn(p, (r) => {
map.set(p, r);
callback();
});
});
this.series(fns)(() => {
const results = ps.map((p) => map.get(p));
map.clear();
done(results);
});
}
}
const task = new Task();
exports2.task = task;
Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
});
//# sourceMappingURL=index.umd.js.map

5

package.json
{
"name": "@feng3d/task",
"version": "0.8.0",
"version": "0.8.1",
"description": "串联或并联一组异步函数为一个异步函数",

@@ -34,3 +34,4 @@ "main": "dist/index.umd.js",

"lib",
"src"
"src",
"tsconfig.json"
],

@@ -37,0 +38,0 @@ "devDependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc