getLineAsync.tri (1084B)
1 !import base as B 2 !import io as IO 3 !import io_text as Text 4 !export main 5 6 -- One child reads a bounded line; only the parent writes. Prompt availability 7 -- does not require input first. EOF is not an empty name, CR is not stripped, 8 -- and neither sleep nor scheduler timing is used to coordinate the prompt. 9 name reader = IO.require (Text.readLine (Text.lineCursor reader) 4096) (reply : case reply of 10 [["line" text _] _] = IO.pure (B.append "Hello, " (B.append text "!\n")) 11 [["eof"] _] = IO.pure "End of input.\n" 12 _ = IO.fail "Invalid line reply") 13 main = IO.io (IO.scope (_ : do IO.require 14 reader <- IO.stdin 15 writer <- IO.stdout 16 spawned <- IO.spawn 0 1 [] (_ : name reader) 17 Text.writeText writer "Please enter your first name: \n(this printed before you typed anything)\n(this second line also printed before you typed anything)\n" 18 case spawned of 19 [_ ticket] = IO.require (IO.join ticket) (outcome : case outcome of 20 ["completed" greeting] = IO.require (Text.writeText writer greeting) IO.pure 21 _ = IO.fail outcome) 22 _ = IO.fail "Invalid name task"))