UNPKG

530 BJavaScriptView Raw
1import { now, requestAnimationFrame, cancelAnimationFrame } from '@tarojs/runtime'
2
3export function cancelTimeout (timeoutID) {
4 cancelAnimationFrame(timeoutID.id)
5}
6
7export function requestTimeout (callback, delay) {
8 const start = now()
9
10 const timeoutID = {
11 id: requestAnimationFrame(tick)
12 }
13
14 function tick () {
15 if (now() - start >= delay) {
16 // eslint-disable-next-line no-useless-call
17 callback.call(null)
18 } else {
19 timeoutID.id = requestAnimationFrame(tick)
20 }
21 }
22
23 return timeoutID
24}