Hi

I have an event listener attached to something which will fire a lot based on some user action that has occured on the page or some javscript change. Unfortunately it will be something like 5 or 6 fires in the space of 250ms and I am only interested in the last fire so I can carry out the resource intensive processing. I'd like to ignore all of the fires before that.

Any way this can be achieved keeping in mind we don't know how many times it will fire.

Recommended Answers

All 3 Replies

I would say no, because if you don't know how many times it will fire, you wont know if the current fire is the last.

could there not be a way to check with milliseconds elapsed since the last check, i.e. if it has taken more than 500ms since a fire has occured it means this 'burst' of fires has stopped?

I don't know..

Yes, this is a "rule" that you could implement. You would need to record the time of each fire (you can overwrite a single variable) and then apply a rule that if a timespan greater than n (500ms in your example) has elapsed between the last recorded fire then this would signify that it was the last fire and take appropriate action.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.