Ruby Timeout::timeout doesn't fire Exception and doesn't return what documented

后端 未结 3 2194
野的像风
野的像风 2021-02-14 09:39

I have this piece of code:

begin
  complete_results = Timeout.timeout(4) do      
    results = platform.search(artist, album_name)
  end
rescue Timeout::Error
           


        
3条回答
  •  忘掉有多难
    2021-02-14 10:20

    According to the documentation:

    If the block execution terminates before sec seconds has passed, it returns true. If not, it terminates the execution and raises exception (which defaults to Timeout::Error)

    This means it only returns true if it's successful, otherwise the variable will not be set (ie it's nil NOT false).

    As far as your example goes, it's definitely timing out for me and getting to the rescue part...

提交回复
热议问题