Sha256: c51fa38847a818e6f178f43c53185012ff795181d2fe3054de2ca7624e728a32

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

require 'thread'

require 'queue_to_the_future/coordinator'
require 'queue_to_the_future/worker'
require 'queue_to_the_future/job'

module QueueToTheFuture
  # The maximum number of workers to create for processing jobs.
  #
  # @return [Fixnum] Default is 15
  def self.maximum_workers
    @@maximum_workers ||= 15
  end
  
  # Setter method for {maximum_workers}
  #
  # @param [Fixnum] number Any integer greater than 0
  # @return [Fixnum] number given
  # @raise [StandardError] If the number given is less than 1
  def self.maximum_workers=(number)
    raise StandardError.new("Bad workforce size: #{number}. Must be at least 1.") unless (number = number.to_i) >= 1
    @@maximum_workers = number
  end
end

module Kernel
  # Main interface for asynchronous job scheduling. (Where the magick begins)
  # 
  # @example
  #   http        = Net::HTTP.new("ia.media-imdb.com")
  #   image_path  = "/images/M/MV5BMTkzNDQyMjc0OV5BMl5BanBnXkFtZTcwNDQ4MDYyMQ@@._V1._SX100_SY133_.jpg"
  #   
  #   image = Future(image_path) do |path|
  #     http.request(Net::HTTP::Get.new(path)).body
  #   end
  # 
  #   # do other things
  #
  #   puts image.size # => 6636
  #
  # @param (see QueueToTheFuture::Job#initialize)
  # @return [QueueToTheFuture::Job] Your proxy into the future
  def Future(*args, &block)
    QueueToTheFuture::Job.new(*args, &block)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
queue_to_the_future-0.1.1 lib/queue_to_the_future.rb