michael@0: var timer = null; // declare timer outside to prevent premature GC michael@0: function handleRequest(request, response) michael@0: { michael@0: response.processAsync(); michael@0: response.setHeader("Content-Type", "text/plain", false); michael@0: michael@0: for (var i = 0; i < 1000; ++i) michael@0: response.write("Hello... "); michael@0: michael@0: timer = Components.classes["@mozilla.org/timer;1"] michael@0: .createInstance(Components.interfaces.nsITimer); michael@0: timer.initWithCallback(function() { michael@0: response.write("world.\n"); michael@0: response.finish(); michael@0: }, 10 * 1000 /* 10 secs */, Components.interfaces.nsITimer.TYPE_ONE_SHOT); michael@0: }