作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这段代码从stdin
获取字符并将它们转换为字符串。使用 hWaitForInput
实现的输入存在超时。我已经包含了 tryIOError
函数来捕获 isEOFError
。当程序运行并且没有发生输入(即正在等待输入)时,它会正确超时。然而,一旦输入一个字符,它就不再超时。无论输入等待时间是多少。
-- get string from stdin
getFrmStdIn :: Int -> IO String
getFrmStdIn timeout = do
inAvail <- tryIOError $ hWaitForInput stdin timeout
let tOut = either (const False) id inAvail
if isLeft inAvail
then return []
else
if not tOut
then die "00 timed out"
else
(:) <$> hGetChar stdin <*> getFrmStdIn timeout
最佳答案
您使用的操作系统和 GHC 版本是什么?
据我所知,最新的 GHC
版本 hWaitForInput
doesn't work on linux当超时不为 0 时根本不会。在 Windows 上,整个 IO 子系统为 "a bit lacking"也是。
关于haskell - hWaitForInput 如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43409494/
这段代码从stdin获取字符并将它们转换为字符串。使用 hWaitForInput 实现的输入存在超时。我已经包含了 tryIOError 函数来捕获 isEOFError。当程序运行并且没有发生输入
我是一名优秀的程序员,十分优秀!