Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 22dc24966a
Fetching contributors…

Cannot retrieve contributors at this time

file 33 lines (28 sloc) 0.543 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
require 'timeout'


class Task
  class << self
    def run(&block)
      new(&block)
    end
    private :new
  end

  attr_accessor :logger

  def initialize(logger = nil, &block)
    @logger = logger || ActiveRecord::Base.logger
    @result = nil
    @thread = Thread.new {
      @result = yield
    }
  end

  def result(timeout = F2P::Config.friendfeed_api_timeout)
    begin
      timeout(timeout) do
        @thread.join
        @result
      end
    rescue Timeout::Error => e
      logger.warn(e)
      @result = nil
    end
  end
end
Something went wrong with that request. Please try again.