I have a jQuery widget, which contains a variable this.options._offset and a function _drawPlot(). When user drag & drop, a function _drawPlot() will be executed and this.options._offset will be updated at the end.
Now the problem is, a user may drag & drop too fast, making the variable _offset not consistent. For example, two drag & drop operations A and B, the execution sequence maybe:
A: plotting
A: update offset
B: plotting
B: update offset
Or:
A: plotting
B: plotting
A: update offset
B: update offset
The value offset is not correct for second case. I thought JS is single threaded and never expected this to happen. It is like semaphore in OS. Or it is just because console.log is cheating me? But anyway, the function _drawPlot(), which makes use of _offset, behaves wrongly.
I know I can throttle the operation, but even after throttling, the problem still exists if _drawPlot() runs for a long time.
Is there a way to control this?
_offsetupdated directly by the_drawPlot()function or by a different handler bound to a sort of "finished plotting" event triggered somewhere? A little bit of code may help