看板 Ajax 關於我們 聯絡資訊
請問一下,最近研究node遇到個問題 假設玩家目前有money : 10, 是否會發生當'updateCoin1' event發出後,執行的query還沒執行callback,就去執行'updateCoin2' event的query, 導致updateCoin1執行callback後,將money變成0,而updateCoin2執行callback把money更新成-10這樣的錯誤, 請問運作機制是我說的這樣嗎??db.query皆會丟到背景執行?? on.(cmd === 'updateCoin1') { db.query('select * from user',function(err, rows){ if(err){ return false; } if(rows.money >= 5){ db.query('update user set money=momey-5',function(err, rows){ if(err){ return false; } return true; }); } }); } on.(cmd === 'updateCoin2') { db.query('select * from user',function(err, rows){ if(err){ return false; } if(rows.money >= 10){ db.query('update user set money=momey-10',function(err, rows){ if(err){ return false; } return true; }); } }); } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 111.248.236.198
fillano:用nodejs + flow control關鍵字google一下 12/07 18:12