Skip to content

Instantly share code, notes, and snippets.

@e7h4n
Created June 28, 2019 07:29
Show Gist options
  • Save e7h4n/6b7ea3e0e0fea1ec6b2f4b07f619c519 to your computer and use it in GitHub Desktop.
Save e7h4n/6b7ea3e0e0fea1ec6b2f4b07f619c519 to your computer and use it in GitHub Desktop.
// 业务方法定义
const getA = function(cb) {
cb(a);
}
const getB = function(a, cb) {
cb(b);
}
const getC = function(a, b, cb) {
cb(c);
}
const getD = function(b, c, cb) {
cb(d);
}
const getE = function(d, cb) {
cb(d);
}
// 依赖关系定义
const depTree = {
a: {
deps: [],
method: getA,
retryLimit: 3,
},
b: {
deps: ['a'],
method: getB,
retryLimit: 3,
},
c: {
deps: ['a', 'b'],
method: getC,
retryLimit: 3,
},
d: {
deps: ['b', 'c'],
method: getD,
retryLimit: 3,
},
main: {
deps: ['d'],
method: getE,
retryLimit: 3,
},
};
depExec(depTree, e => {
console.log(e);
});
// TODO: 解析 depTree,尽可能并行地去拉取数据,对外返回 main 任务的 method 结果
function depExec(tree, cb) {
// fill this
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment