I am writing a webpage with the following structure:
- One section (table A) depends on another section (table B);
- Another section (table B) has elements that require recalculation on each update. The calculation is handled by external tools, and will cause an event when finished.
In order to guarantee correctness, the table need to be updated only after the other table is fully updated (i.e., done with computation). However, I don't know how to effectively achieve this, and I could not find any wait
facility within JavaScript.
For now, I am using the following method:
- Declare a global variable
updated
and make itfalse
; - After the first table received input, I make an empty
while
loop untilupdated
istrue
; - Add an listener, once the calculation is done and the event received, set
updated
totrue
.
This seems unintuitive to me but I cannot think of any other way of doing it. Is there any good ways to do this?
Thanks for any inputs!
setTimeout
which periodically checks the status ofupdated
instead of an emptywhile
loop. – Ledge