Instant search using TextBox and onKeyUp and onKeyDown
===

I would like to make Google Apps Script webapp that search spreadsheet instantly as you type in the TextBox.

The implementation I"m using now is following. For each key up event new search is lauched with the current search string. I'm using delay on the function that onKeyUp is calling and if the onKeyDown is called I try to kill the previous function call and just go with the new. This works sometimes but the search takes different time to complete so the last one to finish is not allways the right one.

I don't know how to solve this task in Google Apps script. This can be implemented using something like this but these functions are not awailable:

    var timer;
    function up(){
      setTimeout(mySpreadsheetSearchFunction, 500);
    }
    function down(){
      clearTimeout (timer);
    }
    
This is the code of the current implementation that is not working correctly:

    function up(){
      var cache = CacheService.getPrivateCache();
      var now = parseInt(cache.get('iterate'));
      Utilities.sleep(500);
      if(parseInt(cache.get('iterate')) !== parseInt(now)){
        return;
      }else{
        search();
      }
      showInGui();
    }

    function down(){
      var cache = CacheService.getPrivateCache();
      cache.put('iterate', 1+parseInt(cache.get('iterate')));
    }

The CacheService is probably wrong tool for this job, what could be beter? Is this the right way to implement something like this?

