[#9445] thread.rb — m_seki@...

18 messages 2000/03/16
[#9446] Re: thread.rb — matz@... (Yukihiro Matsumoto) 2000/03/17

[#9460] Re: thread.rb — m_seki@... 2000/03/21

[#9462] Re: thread.rb — matz@... (Yukihiro Matsumoto) 2000/03/21

まつもと ゆきひろです

[#11281] Re: thread.rb — Masatoshi SEKI <m_seki@...> 2000/10/22

[#9498] timeout しない timeout — ARIMA Yasuhiro <fit0298@...>

有馬です。

20 messages 2000/03/26
[#9506] Re: timeout しない timeout — matz@... (Yukihiro Matsumoto) 2000/03/27

まつもと ゆきひろです

[#9509] Re: timeout しない timeout — gotoken@... (GOTO Kentaro) 2000/03/27

In message "[ruby-dev:9506] Re: timeout しない timeout"

[ruby-dev:9528] Re: timeout しない timeout

From: gotoken@... (GOTO Kentaro)
Date: 2000-03-30 07:11:35 UTC
List: ruby-dev #9528
ごとけんです

In message "[ruby-dev:9526] Re: timeout しない timeout"
    on 00/03/29, ARIMA Yasuhiro <fit0298@fitec.co.jp> writes:

>def timeout(sec)
>  return yield  unless sec
>  begin
>    x = Thread.current
>    y = Thread.start {
>      sleep sec
>      x.raise TimeoutError, "execution expired" if x.status
>    }
>    yield
>  ensure
>    Thread.kill y if y.status
>  end
>end
>
>結果を返すなら、タイムアウトせずに終えたかどうかを返すのでしょうね。

返り値でtimeoutを判定するのはなんか変な気が…

例外が起こったときの値は不定にして、例外が起こらなかったとき
はブロックの値を返すが分かりやすいと思います。たとえば上記の
timeoutはそれを満たしています。

たとえば、以下のような使い方も出来ます。

  begin
    header = timeout(2){socket.gets}
    .....
  rescue TimeoutError
    .....
  end

-- gotoken

In This Thread