@@ -17,31 +17,43 @@ newtype TimeoutId = TimeoutId Int
17
17
derive instance eqTimeoutId :: Eq TimeoutId
18
18
derive instance ordTimeoutId :: Ord TimeoutId
19
19
20
+ foreign import setTimeoutImpl :: Int -> Effect Unit -> Effect TimeoutId
21
+
20
22
-- | Runs an effectful function after the specified delay in milliseconds. The
21
23
-- | returned `TimeoutId` can be used to cancel the timer before it completes.
22
24
-- |
23
25
-- | The timeout delay value is capped at 4ms by the JS API, any value less than
24
26
-- | this will be clamped.
25
- foreign import setTimeout :: Int -> Effect Unit -> Effect TimeoutId
27
+ setTimeout :: Int -> Effect Unit -> Effect TimeoutId
28
+ setTimeout = setTimeoutImpl
29
+
30
+ foreign import clearTimeoutImpl :: TimeoutId -> Effect Unit
26
31
27
32
-- | Cancels a timeout. If the timeout has already been cancelled or has already
28
33
-- | elapsed this will have no effect.
29
- foreign import clearTimeout :: TimeoutId -> Effect Unit
34
+ clearTimeout :: TimeoutId -> Effect Unit
35
+ clearTimeout = clearTimeoutImpl
30
36
31
37
-- | The ID of a timer started with `setInterval`.
32
38
newtype IntervalId = IntervalId Int
33
39
34
40
derive instance eqIntervalId :: Eq IntervalId
35
41
derive instance ordIntervalId :: Ord IntervalId
36
42
43
+ foreign import setIntervalImpl :: Int -> Effect Unit -> Effect IntervalId
44
+
37
45
-- | Runs an effectful function after on a set interval with the specified delay
38
46
-- | in milliseconds between iterations. The returned `IntervalId` can be used
39
47
-- | to cancel the timer and prevent the interval from running any further.
40
48
-- |
41
49
-- | The interval delay value is capped at 4ms by the JS API, any value less
42
50
-- | than this will be clamped.
43
- foreign import setInterval :: Int -> Effect Unit -> Effect IntervalId
51
+ setInterval :: Int -> Effect Unit -> Effect IntervalId
52
+ setInterval = setIntervalImpl
53
+
54
+ foreign import clearIntervalImpl :: IntervalId -> Effect Unit
44
55
45
56
-- | Cancels an interval timer. If the interval has already been cancelled this
46
57
-- | will have no effect.
47
- foreign import clearInterval :: IntervalId -> Effect Unit
58
+ clearInterval :: IntervalId -> Effect Unit
59
+ clearInterval = clearIntervalImpl
0 commit comments