Yet another, a wrapper library of Thread class for easily describing parallel processing.
-
Thread::Task is a configuration that allows you to briefly describe the configuration often used in parallel processing.
-
Thread::Pool limits the number of parallel executions of Thread::Task.
-
Using Kernel#future method, asynchronous process can be described simply.
Add this line to your application’s Gemfile:
gem 'thread-task'And then execute:
$ bundle install
Or install it yourself as:
$ gem install thread-task or $ gem install -l thread-task-x.x.x.gem
require "thread/task"
task = ::Thread::Task.new do
sleep 2
Time.now
end
p task.valueThread::Task.new( *args, pool: nil, &block )
Kernel#future( *args, pool: nil, &block )Kernel#future method can be used with require "thread/task/future".
-
Result:
-
Thread::Task object.
-
-
Parameter:
-
args: Pass args as is to the block.
-
pool: Thread::Pool object. (default: nil)
-
block: callback action.
-
-
Block Parameter:
-
args: Treat args as local variables specific to that thread.
-
Thread::Task#value-
Result:
-
The execution result of the block.
-
-
Parameter:
-
none.
-
Thread::Pool.new( count )-
Result:
-
Thread::Pool object.
-
-
Parameter:
-
count: Max count of parallel executions.
-
Bug reports and pull requests are welcome on GitHub at https://github.com/arimay/thread-task.
The gem is available as open source under the terms of the MIT License.
Copyright (c) ARIMA Yasuhiro <[email protected]>