0
我有2個基本上與嵌套在光纖中的級聯函數調用相同的scipt。錯誤:wait.for只能在光纖內調用
這其中有三個電話(解析的Tx在blockchain)的作品完美
wait.launchFiber(blockchain)
function blockchain() {
foreach block {
parseBlock (blockIndex)
}
}
function parseBlock(blockIndex) {
foreach Tx in block {
parseTx(txHash)
}
}
function parseTx (txHash) {
if (txHashInDB(txHash)) {
do something
}
}
function txHashInDB (txHash) {
var theTx = wait.forMethod(Tx, 'findOne', {'hash': txHash});
return (theTx) ? true : false;
}
然後,我必須做的內存池類似的東西。在這種情況下,我沒有塊,僅成交,所以我只有2個電話,我得到這個錯誤信息:
錯誤:wait.for只能被稱爲纖維內部
wait.launchFiber(watchMempool);
function watchMempool() {
web3.eth.filter('pending', function (error, txHash) {
parseTx(txHash);
});
}
function parseTx (txHash) {
if (txHashInDB(txHash)) {
do something
}
}
function txHashInDB (txHash) {
var theTx = wait.forMethod(Tx, 'findOne', {'hash': txHash});
return (theTx) ? true : false;
}
我不明白問題是什麼。這兩個腳本具有相同的結構!
恩,除非我在這裏錯過了一些東西,你根本沒有在第二個腳本中啓動光纖(用'wait.launchFiber')? – d0gb3r7
你是對的,我忘了包括光纖的開發,所以代碼應該是:wait.launchFiber(watchMempool); function watchMempool(){web3.eth.filter(...)} 我在我的問題中做了chande。 :-) – jfjobidon
看來,當我調用過濾器的腳本離開纖維工作區... – jfjobidon