Debian Codegraph @

lib/cml/tests/io-manager.sml

raw
1 structure Main =
2 struct
3 local
4 val (TextPrimIO.RD reader, _) =
5 TextIO.StreamIO.getReader (TextIO.getInstream TextIO.stdIn)
6 val iodesc = Option.valOf (#ioDesc reader)
7 val polldesc = OS.IO.pollIn (Option.valOf (OS.IO.pollDesc iodesc))
8 in
9 val readVecNB = Option.valOf (#readVecNB reader)
10 val readStdInEvt = IOManager.ioEvt polldesc
11 end
12
13 fun echoOrTimeoutLoop () =
14 let
15 val () = TextIO.print "Start of loop:\n"
16 in
17 CML.select
18 [ CML.wrap (readStdInEvt, fn (_: IOManager.poll_info) =>
19 ( TextIO.print "Received stdin event\n"
20 ; case readVecNB 1000 of
21 SOME s => TextIO.print ("Read string: " ^ s ^ "\n")
22 | NONE => TextIO.print "Read will block\n"
23 ))
24 , CML.wrap (CML.timeOutEvt (Time.fromSeconds 3), fn () =>
25 TextIO.print "Timed out\n")
26 ];
27 echoOrTimeoutLoop ()
28 end
29
30 fun cmlMain () =
31 echoOrTimeoutLoop ()
32 handle e =>
33 TextIO.print
34 ("Exception name: " ^ exnName e ^ " message: " ^ exnMessage e ^ "\n")
35
36 fun doit _ =
37 let
38 val status = RunCML.doit (cmlMain, NONE)
39 in
40 if OS.Process.isSuccess status then print "Exit success\n"
41 else print "Exit failure\n"
42 end
43 end