制作状态机的承诺链?
chain of promsies to make a state machine?
我有这个模式:(其中 (Pi) 是不同的承诺)
// STEP 1 : Show the help modal and the instruction modal after.
P1.then(() => {
return P2
})
// STEP 2 : Start calibration
.then(() => {
return P3;
})
// STEP 3 : Wait until all points have been clicked on
.then(() => {
doSomething();
});
我制作了一种状态机。
最后,在 doSomething() 中,如果校准不成功,我想回到我的第二个,否则结束链。
我不知道该怎么做...你有什么想法吗?
像这样的事情怎么样:
const steps = {
one: async () => {
await something();
steps.two();
}
two: async () => {
try {
const results = await somethingElse();
steps.three(results);
} catch(e) {
// TODO display error message
steps.one();
}
}
three: async () => {
// do whatever
}
}
不知道这样的结构是否对您有帮助。
我有这个模式:(其中 (Pi) 是不同的承诺)
// STEP 1 : Show the help modal and the instruction modal after.
P1.then(() => {
return P2
})
// STEP 2 : Start calibration
.then(() => {
return P3;
})
// STEP 3 : Wait until all points have been clicked on
.then(() => {
doSomething();
});
我制作了一种状态机。 最后,在 doSomething() 中,如果校准不成功,我想回到我的第二个,否则结束链。
我不知道该怎么做...你有什么想法吗?
像这样的事情怎么样:
const steps = {
one: async () => {
await something();
steps.two();
}
two: async () => {
try {
const results = await somethingElse();
steps.three(results);
} catch(e) {
// TODO display error message
steps.one();
}
}
three: async () => {
// do whatever
}
}
不知道这样的结构是否对您有帮助。