зеркало из https://github.com/mozilla/pjs.git
Bug 633566 - Prevent the timer to be eaten alive by the GC. r=bz a=tests
This commit is contained in:
Родитель
83a81f86c7
Коммит
464fbc5a20
|
@ -25,6 +25,12 @@ const IMAGE_DATA =
|
|||
0x49, 0x45, 0x4E, 0x44, 0xAE, 0x42, 0x60, 0x82,
|
||||
];
|
||||
|
||||
/**
|
||||
* The timer is needed when a delay is set. We need it to be out of the method
|
||||
* so it is not eaten alive by the GC.
|
||||
*/
|
||||
var timer;
|
||||
|
||||
function handleRequest(request, response) {
|
||||
var query = {};
|
||||
request.queryString.split('&').forEach(function (val) {
|
||||
|
@ -40,16 +46,20 @@ function handleRequest(request, response) {
|
|||
stream.writeByteArray(IMAGE_DATA, IMAGE_DATA.length);
|
||||
}
|
||||
|
||||
if ("delay" in query) {
|
||||
response.processAsync();
|
||||
const nsITimer = Components.interfaces.nsITimer;
|
||||
|
||||
var timer = Components.classes["@mozilla.org/timer;1"].createInstance(nsITimer);
|
||||
timer.initWithCallback(function() {
|
||||
imageWrite();
|
||||
response.finish();
|
||||
}, query["delay"], nsITimer.TYPE_ONE_SHOT);
|
||||
} else {
|
||||
// If there is no delay, we write the image and leave.
|
||||
if (!("delay" in query)) {
|
||||
imageWrite();
|
||||
return;
|
||||
}
|
||||
|
||||
// If there is a delay, we create a timer which, when it fires, will write
|
||||
// image and leave.
|
||||
response.processAsync();
|
||||
const nsITimer = Components.interfaces.nsITimer;
|
||||
|
||||
timer = Components.classes["@mozilla.org/timer;1"].createInstance(nsITimer);
|
||||
timer.initWithCallback(function() {
|
||||
imageWrite();
|
||||
response.finish();
|
||||
}, query["delay"], nsITimer.TYPE_ONE_SHOT);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче