Skip to content

Instantly share code, notes, and snippets.

@axelerator
Created February 2, 2020 04:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save axelerator/6e41cd3668ee9f07d2be78d2765c881d to your computer and use it in GitHub Desktop.
Save axelerator/6e41cd3668ee9f07d2be78d2765c881d to your computer and use it in GitHub Desktop.
Asyn user input
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