Skip to content

Java's ExecutorService inspired threading library for ruby

License

Notifications You must be signed in to change notification settings

signine/executor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Executor

This is a library for using threads with a similar interface to Java's ExecutorService.

Usage

require 'executor'

ThreadPool

Create a pre-forked thread pool with 4 threads

pool = Executor::ThreadPool.new(4)

Submit tasks

future = pool.submit do
  puts "Working..."
  1 + 1
end

Get the result. This blocks until the result is ready

puts future.get
# 2

Shutdown thread pool and wait for completion of all tasks

pool.shutdown
pool.await_termination

Shutdown thread pool immediately and return the list of tasks waiting execution

pool.shutdown!

Worker

Create a pre-forked thread pool that executes the given block but with arguments given by calling submit

worker = Executor::Worker(4) do |arg1, arg2|
  arg1 + arg2
end

future = worker.submit(10, 20)
puts future.get
# 30

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/executor.

License

The gem is available as open source under the terms of the MIT License.

About

Java's ExecutorService inspired threading library for ruby

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published