Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A tunable work queue, designed to coordinate work between a producer and a pool of worker threads.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Gemfile.lock
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 brodock-work_queue.gemspec
README.rdoc

Description

A work queue is designed to coordinate work between a producer and a pool of worker threads. When some task needs to be performed, the producer adds an object containing the task routine to the work queue. If the work queue is full, the producer will block until a worker thread removes an object from the queue. Eventually, one of the worker threads removes the object from the work queue and executes the routine. If the work queue is empty, a worker thread will block until an object is made available by the producer.

Work queues are useful for several reasons:

  • To easily perform tasks asynchronously and concurrently in your application;

  • To let you focus on the work you actually want to perform without having to worry about the thread creation and management;

  • To minimize overhead, by reusing previously constructed threads rather than creating new ones;

  • To bound resource use, by setting a limit on the maximum number of simultaneously executing threads;

Usage

Install the gem:

gem install brodock-work_queue

Or place this on your Gemfile:

gem "brodock-work_queue", :require => "work_queue"

Run the code:

require 'rubygems'
require 'work_queue'
wq = WorkQueue.new
wq.enqueue_b { puts "Hello from the WorkQueue" }
wq.join

Note that you generally want to bound the resources used:

# Limit the maximum number of simultaneous worker threads
WorkQueue.new(10)
# Limit the maximum number of queued tasks
WorkQueue.new(nil,20)
Something went wrong with that request. Please try again.