0

How to raise timeout error using koala gem for Facebook in Rails ?

if anybody knows, please let me know.

Малъ Скрылевъ
  • 16,187
  • 5
  • 56
  • 69
Kushal
  • 218
  • 2
  • 12

2 Answers2

2

You can use ruby's Timeout module as follows:

require 'timeout'
begin
   status = Timeout::timeout(5) do
      @koala_api.get_connection 'me', :feed
   end
rescue Timeout::Error
   # do something on timeout
end
Малъ Скрылевъ
  • 16,187
  • 5
  • 56
  • 69
  • Timeout: is not thread-safe. And can lead to unexpected. behavior in a multi-thread scenario as Kidd Said. – Nando Aug 10 '18 at 02:16
  • @NandoSousa you are just offending, because of you have not prooved you statement, so your opinion must be thrown to trash... – Малъ Скрылевъ Aug 10 '18 at 11:15
  • Take a look: https://medium.com/@adamhooper/in-ruby-dont-use-timeout-77d9d4e5a001 https://jvns.ca/blog/2015/11/27/why-rubys-timeout-is-dangerous-and-thread-dot-raise-is-terrifying/ https://www.mikeperham.com/2015/05/08/timeout-rubys-most-dangerous-api/ Don't be offended, be humble enough to accept that you're wrong instead. – Nando Aug 11 '18 at 13:51
  • @NandoSousa that papers show imagine on the topic only, without any proof, so thst is the only conjecture and speculations... so you can't indeed downvote because of proofless speculations – Малъ Скрылевъ Aug 13 '18 at 09:50
0

The best way to do that is: Koala.http_service.http_options = {request: {open_timeout: 1, timeout: 1}}

Nando
  • 747
  • 7
  • 23