88bea6ed8455b8ce18da1d74893462650e1ad99c
[platform/framework/web/crosswalk-tizen.git] /
1 define(['../time/now', './timeout', '../array/append'], function (now, timeout, append) {
2
3     /**
4      * Ensure a minimum delay for callbacks
5      */
6     function awaitDelay( callback, delay ){
7         var baseTime = now() + delay;
8         return function() {
9             // ensure all browsers will execute it asynchronously (avoid hard
10             // to catch errors) not using "0" because of old browsers and also
11             // since new browsers increase the value to be at least "4"
12             // http://www.whatwg.org/specs/web-apps/current-work/multipage/timers.html#dom-windowtimers-settimeout
13             var ms = Math.max(baseTime - now(), 4);
14             return timeout.apply(this, append([callback, ms, this], arguments));
15         };
16     }
17
18     return awaitDelay;
19
20 });