I am using the JavaScript API in my truffle tests to get the events from the contract: https://github.com/ethereum/wiki/wiki/JavaScript-API#contract-allevents
const allEvents = instance.allEvents({
fromBlock: 0,
toBlock: 'latest'
});
allEvents.watch((err, res) => {
console.log(res);
});
It never stops listening so I tried adding this to the end:
allEvents.stopWatching()
The listening stops, but nothing is ever logged, so I tried adding a delay:
setTimeout(allEvents.stopWatching, 1000);
But the listening doesn't stop.
How do I stop listening after all the events emitted till now have been retrieved?
.stopWatching()
immediately after.watch()
it will stop there before any event, setTimeout might not work becauseallEvents.stopWatching
is a function without a binding. – Ismael Sep 18 '18 at 15:27