-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker_timeout.js
More file actions
64 lines (59 loc) · 1.25 KB
/
worker_timeout.js
File metadata and controls
64 lines (59 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
var INTERVAL = 0,
TIMEOUT = 1,
ANIMATION = 2,
timeout_map = {},
interval_map = {},
animationFrame = false,
create,
b_id,
stop;
this.addEventListener('message',function (message) {
var data = message.data,map;
data.type === TIMEOUT && (
create = setTimeout,
stop = clearTimeout,
map = timeout_map
) ||
data.type === INTERVAL && (
create = setInterval,
stop = clearInterval,
map = interval_map
) ||
data.type === ANIMATION && (
create = function (frame) {
if (animationFrame === false) {
animationFrame = setTimeout(function () {
if (animationFrame) {
animationFrame = false;
self.postMessage('a');
}
},data.time);
}
return false;
},
stop = function () {
animationFrame !== false && (
clearTimeout(animationFrame),
animationFrame = false)
}
);
data.type !== ANIMATION && data.clear && (
stop(map[data.id]),
delete map[data.id],
true
) ||
(
b_id = data.time ? create(function () {
if (map[data.id]) {
self.postMessage(data.id);
data.type === TIMEOUT && (delete map[data.id]);
}
},data.time) : create(function () {
if (map[data.id]) {
self.postMessage(data.id);
data.type === TIMEOUT && (delete map[data.id]);
}
}),
b_id !== false && (map[data.id]=b_id)
);
});