-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpromises.js
39 lines (32 loc) · 844 Bytes
/
promises.js
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
(function() {
var requestAnimationFrame_ = window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.msRequestAnimationFrame;
function animationFrame() {
return new Promise(function(resolve) {
requestAnimationFrame_(resolve);
});
}
function timer(interval) {
return new Promise(function(resolve) {
window.setTimeout(resolve, interval);
});
}
window.Promises = {
animationFrame: animationFrame,
timer: timer,
};
})();
function repeat_until(body, condition) {
function loop() {
return body().then(function() {
if (!condition())
return loop();
});
}
return loop();
}
function handle_error(error) {
throw error;
}