javascript - Within Google apps script, what replaces Utilities.sleep() to prevent double clicks? -


i'm writing add-on within google docs script. sidebar, writes info doc, not spreadsheet. depending on connection speeds, doc updated between <1 sec , 5 secs info.

my issue user double clicks. can disable button; however, script takes less second complete, yet doc updated in > 1 sec. finished script enables button. user clicks button again , script attempts write info first time. end result double entry.

my solution thoughts were: 1. wait or pause 2. callback function or 3. locks.

issues: callback: couldn't figure out event/input use tell script unlock button now. infinite loop checks forever until doc has been updated, didn't seem solid solution. lock: there isn't there wait. can wait function become available, isn't problem. problem script done fast relative doc update.

any thoughts?

thanks.

i think of solution:

each time script called, compare document's current text text passed script on previous call.

some pseudo code:

var previoustext = "";  function addentry() {     var body = documentapp.getactivedocument().getbody();     var currenttext = body.gettext();      if (currenttext === previoustext) {         // enable button here         return;     }      // add entry document , currenttext     // ...     // ...      previoustext = currenttext; // save text future checks      // enable button here }  function onbuttonclick(e) {     addentry();     // disable button here } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -