Re: 程式大師請進
※ 引述《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)
--
▉▏
▉▏
◢ ▊▎ ◣
◤ ▄▆▄ ◥
◥ ◥ ◤ ◤
▄ ▄
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.129.201.29 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1699359073.A.409.html
推
11/07 20:12,
2年前
, 1F
11/07 20:12, 1F
討論串 (同標題文章)