Skip to content
This repository was archived by the owner on May 8, 2023. It is now read-only.

Commit

Permalink
Debounce event listener in events example
Browse files Browse the repository at this point in the history
  • Loading branch information
chmanie committed Apr 19, 2022
1 parent 7d451fc commit b1c191f
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions examples/browser/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,19 @@ const setupEventListener = (
colonyAddress,
);

let i = 0;

colonyEvents.provider.on('block', async (no) => {
const events = await colonyEvents.getMultiEvents([domainAdded], {
fromBlock: no,
toBlock: no,
});
if (events.length) callback(events);
i += 1;
// Only get events every 5 blocks to debounce this a little bit
if (i === 4) {
const events = await colonyEvents.getMultiEvents([domainAdded], {
fromBlock: no - i,
toBlock: no,
});
if (events.length) callback(events);
i = 0;
}
});
};

Expand Down

0 comments on commit b1c191f

Please sign in to comment.