Entry 31975

pn_timed_loops

   

Submitted by anonymous on Jan. 30, 2012 at 5:40 p.m.
Language: JavaScript. Code size: 580 bytes.

      /**
       * Process a large group of data asynchronsly and without locking up the UI
       * thread. Process as much data as possible within 50ms
       **/
      (function() {
        setTimeout(function() {
          var start = +new Date();

          do {
            filter_product(products.shift());
          } while(products.length > 0 && (+new Date() - start < 50));

          if (products.length > 0) {
            setTimeout(arguments.callee, 25);
          }
          else {
            callback();
          }

        }, 25);
      })()

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).