Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-27898

iOS: Race condition in setTimeout/clearTimeout (regression)

    Details

      Description

      There seem to be a critical regression regarding intervals in SDK 8 and 9 (so maybe caused between SDK 7 and 8?). See the following vanilla Node.js test case for reference (using a classic throttling mechanism):

      let searchTimeout;
       
      function search(value) {
      	if (searchTimeout) {
      		console.warn('Abort request');
      		clearTimeout(searchTimeout);
      	}
       
      	searchTimeout = setTimeout(() => {
              console.warn('Start search: ' + value);
      	}, 500);
      }
       
      function sleep(ms) {
          return new Promise(resolve => setTimeout(resolve, ms));
      }
       
      (async function () {
          search('m');
          search('me');
          search('mep');
      }());
      

      The expected console output is:

      Abort request
      Abort request
      Start search: mep
      

      But on iOS, the kroll timer manager has different plans with us:

      Abort request
      Start search: m
      Start search: mep
      

      Here is the app test case (wrapped into a quick i/o UI):

      let searchTimeout;
       
      function search(value) {
      	if (searchTimeout) {
      		console.warn('Abort request');
      		clearTimeout(searchTimeout);
      	}
       
      	searchTimeout = setTimeout(() => {
              console.warn('Start search: ' + value);
      	}, 500);
      }
       
      var win = Ti.UI.createWindow({
          backgroundColor: '#fff'
      });
       
      var btn = Ti.UI.createButton({
          title: 'Test'
      });
       
      btn.addEventListener('click', function onClick() {
          search('m')
          search('me')
          search('mep')
      });
       
      win.add(btn);
      win.open();
      

      Notably, iOS does something wrong here. And Android works just fine (like Node.js).

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jvennemann Jan Vennemann
                Reporter:
                hknoechel Hans Knöchel
                Reviewer:
                Vijay Singh
              • Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

                  • Backbone Issue Sync is enabled for your project, but we do not have any synchronization info for this issue.

                    Git Integration