Skip to content

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

Discussion options

You must be logged in to vote

@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;

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.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by software-dev2010
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants