2009/12/03

haskell timeout

プログラミング Haskell って素敵本も買ってみて、
ちょいちょい「お勉強」してるんですが
Haskell で timeout したくなったらどうしよう!?
心配性なので事前に調べておかないと気になって仕方がありません
ググってみました

System.Timeout
timeout :: Int -> IO a -> IO (Maybe a)
何マイクロ秒待つか指定して
IO しようとして、失敗すると Nothing 返ってくるっぽい

試してみた
Prelude Network.HTTP System.Timeout> timeout (3*10^6) $ simpleHTTP $ getRequest "http://10.0.0.1/"
Nothing
Prelude Network.HTTP System.Timeout> timeout (3*10^6) $ simpleHTTP $ getRequest "http://google.com/"
Just (Right HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/
Content-Type: text/html; charset=UTF-8
Date: Sat, 05 Dec 2009 04:49:50 GMT
Expires: Mon, 04 Jan 2010 04:49:50 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 219
X-XSS-Protection: 0
Connection: close

)
Prelude Network.HTTP System.Timeout>
何だこの最後の )Just ( の pair の ) じゃ
でもまぁ、待ててるみたいでした
Network.HTTP に timeout がある気がしないでもないけど、いつか調べよう

0 件のコメント:

コメントを投稿