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);
break;
case 'clearInterval':
clearInterval(fakeIdToId[fakeId]);
delete fakeIdToId[fakeId];
if (fakeIdToId.hasOwnProperty (fakeId)) {
clearInterval(fakeIdToId[fakeId]);
delete fakeIdToId[fakeId];
}
break;
case 'setTimeout':
fakeIdToId[fakeId] = setTimeout(function () {
postMessage({fakeId: fakeId});
if (fakeIdToId.hasOwnProperty (fakeId)) {
delete fakeIdToId[fakeId];
}
}, time);
break;
case 'clearTimeout':
clearTimeout(fakeIdToId[fakeId]);
delete fakeIdToId[fakeId];
if (fakeIdToId.hasOwnProperty (fakeId)) {
clearTimeout(fakeIdToId[fakeId]);
delete fakeIdToId[fakeId];
}
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}}