X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=stimer%2Ftest.icl;fp=stimer%2Ftest.icl;h=3bc5d32dff66d9c3fe63bf3f36eef87e7c6f5c68;hb=b2a4b7c5c620e9d85bda8afa1c5e804ee98ffd89;hp=0000000000000000000000000000000000000000;hpb=acf65f233c22c3eb03ff43805d8065f5ad5a5b53;p=clean-tests.git diff --git a/stimer/test.icl b/stimer/test.icl new file mode 100644 index 0000000..3bc5d32 --- /dev/null +++ b/stimer/test.icl @@ -0,0 +1,29 @@ +module test + +import StdFunc => qualified return +import Data.Func +import System.Time +import iTasks +import iTasks.Internal.IWorld + +Start w = flip startEngine w + $ foreverSt 0 \i-> + waitForSTimer 0.1 + -|| viewInformation () [] (toString i +++ "th waitForSTimer") + >>| treturn (i+1) + +waitForSTimer :: Real -> Task () +waitForSTimer secondsToWait += get currentTimespec + >>= \ts->watch (sdsFocus {start=ts,interval=realToTs secondsToWait} iworldTimespec) + >>* [OnValue (ifValue (\t->t > ts+realToTs secondsToWait) \_->treturn ())] +where + realToTs :: Real -> Timespec + realToTs t = + {tv_sec = floor t + ,tv_nsec = toInt $ (t - toReal (floor t)) * 1E9 + } + floor :: Real -> Int + floor x + | toReal (toInt x) == x = (toInt x) + | otherwise = toInt (x - 0.5)