-
[clean-tests.git] / old / stimer / test.icl
1 module test
2
3 import StdFunc => qualified return
4 import Data.Func
5 import System.Time
6 import iTasks
7 import iTasks.Internal.IWorld
8
9 Start w = flip startEngine w
10 $ foreverSt 0 \i->
11 waitForSTimer 0.1
12 -|| viewInformation () [] (toString i +++ "th waitForSTimer")
13 >>| treturn (i+1)
14
15 waitForSTimer :: Real -> Task ()
16 waitForSTimer secondsToWait
17 = get currentTimespec
18 >>= \ts->watch (sdsFocus {start=ts,interval=realToTs secondsToWait} iworldTimespec)
19 >>* [OnValue (ifValue (\t->t > ts+realToTs secondsToWait) \_->treturn ())]
20 where
21 realToTs :: Real -> Timespec
22 realToTs t =
23 {tv_sec = floor t
24 ,tv_nsec = toInt $ (t - toReal (floor t)) * 1E9
25 }
26 floor :: Real -> Int
27 floor x
28 | toReal (toInt x) == x = (toInt x)
29 | otherwise = toInt (x - 0.5)