/
sanity_check.hs
59 lines (51 loc) · 1.33 KB
/
sanity_check.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/local/bin/stack
{- stack
runghc
--resolver lts-13.13
--package reactive-tomato
-}
{-# LANGUAGE OverloadedStrings #-}
module Main
( main
)
where
import Control.Concurrent
import Control.Concurrent.Async
import Control.Monad
import System.IO
import Reactive.Tomato as RT
import Reactive.Tomato.Time
import Reactive.Tomato.Remote
main :: IO ()
main = checkEvent
checkThrottling :: IO ()
checkThrottling = do
timer <- every $ milli 100
let e0 = throttle timer $ foldp (+) 0 (RT.repeat 1)
let e1 = RT.take 10 e0
xs <- interpret e1
print xs
checkRemote :: IO ()
checkRemote = do
let cnt = foldp (+) 0 (RT.repeat (1 :: Int))
updateTimer <- every $ milli 10
let updates = throttle updateTimer cnt
cnt1 <- runCluster defaultLocal $ do
-- This is useful to eliminate explicit sid construction.
-- If there's a sid which will be reuse,
-- calling 'remote' will inference the sid phantom type as well as the signal type.
sid0 <- sid "cnt0"
-- Spawn is non-blocking and you can't.
spawn sid0 updates
remote sid0
event <- changes cnt1
react (filterJust event) print
checkEvent :: IO ()
checkEvent = do
hSetBuffering stdout LineBuffering
let e1 = generate [1 .. 10]
signal <- newSignal 0 e1
e2 <- changes signal
e3 <- changes signal
let e4 = e2 `union` e3
react (RT.take 10 e4) print