Re: 程式大師請進

作者: eight0 (欸XD)   2023-11-07 20:11:11
※ 引述《SecondRun (南爹摳打)》之銘言:
: 我們專案傳protocol的方式是
: Xprotocol.RegisterOnReceive(() => action);
: Xprotocol.Send();
: 這樣的感覺
: 不過如果會依賴上一個protocol 連續幾個protocol就會變成這樣
: Xprotocol.RegisterOnReceive(() =>
: {
: Yprotocol.RegisterOnReceive(() =>
: {
: Zprotocol.RegisterOnReceive(() => action);
: Zprotocol.Send();
: });
: Yprotocol.Send();
: });
: Xprotocol.Send();
: 在用的時候已經有點感受到波動拳的力量了
: 除此以外還很難讀==
: 有沒有除了async以外的解法啊
function prepareProtocols(protocols, callback) {
function deque() {
if (protocols.length) {
const p = protocols.shift();
p.RegisterOnReceive(deque);
p.Send();
} else {
callback();
}
}
deque();
}
prepareProtocols([Xprotocol, Yprotocol, Zprotocol], () => action)
作者: SecondRun (雨夜琴聲)   2023-11-07 20:12:00

Links booklink

Contact Us: admin [ a t ] ucptt.com