Lesson 9: Why the async function is executed immediately and why it takes few seconds after event is emitted until the listener is executed #5712
-
Hello, I'm not an expert in JavaScript and I want to ask you why the async function is executed immediately. This Promise has a parameter that is an async function, and from what I know an async function isn't executed immediately, it is executed when it is called, not when it is declared, but in this case I see that it is executed immediately. I don't understand why it is executed immediately.
In the hardhat.config.js is configured a timeout for listener. I didn't understand very well how the listener knows about this field timeout.
And another question is why it takes a couple of seconds after the event is emitted until the listener is executed. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
@software-dev2010 You must be working on a local network due to that it is fast. And how it knows about the timeout so it is all configurations by hardhat. And why it takes seconds after await vrfCoordinatorV2Mock.fulfillRandomWords(
txReceipt.events[1].args.requestId,
raffle.address
); then smart contract's emit event so it gove here; raffle.once("WinnerPicked", async () => {
console.log("Found the event!");
try {
...
} catch (e) {
reject(e);
}
resolve();
}); and then it resolve the promise so all of this execution takes these seconds. |
Beta Was this translation helpful? Give feedback.
@software-dev2010 You must be working on a local network due to that it is fast. And how it knows about the timeout so it is all configurations by hardhat. And why it takes seconds after
fulfillRandomWords
call so first it completes this call;then smart contract's emit event so it gove here;
and then it resolve the promise so all of this execution takes these seconds.