-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMain.idr
42 lines (35 loc) · 1 KB
/
Main.idr
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
module Main
import Erlang
%default total
||| Helper function used to simulate delay.
sleep : Int -> IO ()
sleep ms =
ignore $ erlCall "timer" "sleep" [ms]
covering
loop : IO ()
loop = do
Just (MkTuple2 from msg) <- erlReceive 5000 Nothing
(map Just (tuple2 pid atom) <|>
(exact (MkAtom "stop") *> pure Nothing))
| Nothing => putStrLn "[LOOP] Loop ended"
putStrLn ("[LOOP] Message received: " ++ show msg)
sleep 1000
currentPid <- erlSelf
erlSend from (MkTuple2 currentPid msg)
loop
covering
main : IO ()
main = do
loopPid <- erlSpawnLink loop
putStrLn "[MAIN] Loop spawned"
currentPid <- erlSelf
erlSend loopPid (MkTuple2 currentPid (MkAtom "hello"))
putStrLn "[MAIN] Waiting on message from loop"
Just (MkTuple2 from msg) <- erlReceive 5000 Nothing
(map Just (tuple2 pid atom))
| Nothing => do
putStrLn ("[MAIN] Timed out")
sleep 10000
putStrLn ("[MAIN] Message received: " ++ show msg)
erlSend loopPid (MkAtom "stop")
putStrLn "[MAIN] Program ended"