Checking fake id in list before removing (clearTimeout, clearInterval) in worker. Removing fake id from list after setTimeout callback was called in worker. Minified version.

This commit is contained in:
turuslan 2015-07-10 21:08:01 +05:00
parent 1177ef0328
commit 3b71d4f731
2 changed files with 12 additions and 5 deletions

View File

@ -14,17 +14,24 @@ onmessage = function (event) {
}, time); }, time);
break; break;
case 'clearInterval': case 'clearInterval':
clearInterval(fakeIdToId[fakeId]); if (fakeIdToId.hasOwnProperty (fakeId)) {
delete fakeIdToId[fakeId]; clearInterval(fakeIdToId[fakeId]);
delete fakeIdToId[fakeId];
}
break; break;
case 'setTimeout': case 'setTimeout':
fakeIdToId[fakeId] = setTimeout(function () { fakeIdToId[fakeId] = setTimeout(function () {
postMessage({fakeId: fakeId}); postMessage({fakeId: fakeId});
if (fakeIdToId.hasOwnProperty (fakeId)) {
delete fakeIdToId[fakeId];
}
}, time); }, time);
break; break;
case 'clearTimeout': case 'clearTimeout':
clearTimeout(fakeIdToId[fakeId]); if (fakeIdToId.hasOwnProperty (fakeId)) {
delete fakeIdToId[fakeId]; clearTimeout(fakeIdToId[fakeId]);
delete fakeIdToId[fakeId];
}
break; break;
} }
} }

View File

@ -1 +1 @@
var f={},p=postMessage;onmessage=function(e){var d=e.data,i=d.i,t=d.hasOwnProperty('t')?d.t:0;switch(d.n){case'a':f[i]=setInterval(function(){p(i)},t);break;case'b':clearInterval(f[i]);delete f[i];break;case'c':f[i]=setTimeout(function(){p(i)},t);break;case'd':clearTimeout(f[i]);delete f[i];break}} var f={},p=postMessage,r='hasOwnProperty';onmessage=function(e){var d=e.data,i=d.i,t=d[r]('t')?d.t:0;switch(d.n){case'a':f[i]=setInterval(function(){p(i)},t);break;case'b':if(f[r](i)){clearInterval(f[i]);delete f[i]}break;case'c':f[i]=setTimeout(function(){p(i);if(f[r](i))delete f[i]},t);break;case'd':if(f[r](i)){clearTimeout(f[i]);delete f[i]}break}}