Created
February 2, 2020 04:24
-
-
Save axelerator/6e41cd3668ee9f07d2be78d2765c881d to your computer and use it in GitHub Desktop.
Asyn user input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main = do | |
hSetBuffering stdin NoBuffering | |
hSetEcho stdin False | |
mVar <- newMVar "" | |
putStrLn "Go" | |
runAfterDelay 1000000 (appender mVar "foo") | |
runAfterDelay 2000000 (appender mVar "bar") | |
typer mVar | |
putStrLn "Main done" | |
appender mVar x = | |
modifyMVar_ mVar $ \s -> do | |
putStrLn (x ++ s) | |
return (x ++ s) | |
typer mVar = do | |
c <- getChar | |
modifyMVar_ mVar $ \s -> do | |
putStrLn (c:s) | |
return (c:s) | |
if c == 'q' then | |
return () | |
else | |
typer mVar | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment