threadify 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. data/README +9 -4
  2. data/README.erb +5 -0
  3. data/lib/threadify.rb +15 -1
  4. data/threadify.gemspec +1 -1
  5. metadata +2 -2
data/README CHANGED
@@ -64,9 +64,9 @@ SAMPLES
64
64
  ~ > ruby sample/a.rb
65
65
 
66
66
  ---
67
- without threadify: 12.6283850669861
67
+ without threadify: 10.1121168136597
68
68
  ---
69
- with threadify: 1.93842315673828
69
+ with threadify: 8.11967301368713
70
70
 
71
71
 
72
72
  <========< sample/b.rb >========>
@@ -118,9 +118,9 @@ SAMPLES
118
118
  ~ > ruby sample/b.rb
119
119
 
120
120
  ---
121
- without threadify: 22.8657438755035
121
+ without threadify: 20.6975500583649
122
122
  ---
123
- with threadify: 0.967911005020142
123
+ with threadify: 0.923933982849121
124
124
  ---
125
125
  :needle: 42
126
126
  :a: 42
@@ -130,6 +130,11 @@ SAMPLES
130
130
 
131
131
 
132
132
  HISTORY
133
+ 1.3.0
134
+ - added Threadify(*args, &block) method to execute arbitrary code in parallel
135
+
136
+ Threadify(8){ puts Thread.current.object_id }.size #=> 8
137
+
133
138
  1.1.0
134
139
  - added ability to specify arbitrary iterator (not only each)
135
140
  [0,1,2,3].threadify(:each_slice, 2){|ary| ary}
data/README.erb CHANGED
@@ -22,6 +22,11 @@ SAMPLES
22
22
 
23
23
 
24
24
  HISTORY
25
+ 1.3.0
26
+ - added Threadify(*args, &block) method to execute arbitrary code in parallel
27
+
28
+ Threadify(8){ puts Thread.current.object_id }.size #=> 8
29
+
25
30
  1.1.0
26
31
  - added ability to specify arbitrary iterator (not only each)
27
32
  [0,1,2,3].threadify(:each_slice, 2){|ary| ary}
data/lib/threadify.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Threadify
2
- Threadify::VERSION = '1.2.0' unless defined?(Threadify::VERSION)
2
+ Threadify::VERSION = '1.3.0' unless defined?(Threadify::VERSION)
3
3
  def Threadify.version() Threadify::VERSION end
4
4
 
5
5
  require 'thread'
@@ -18,6 +18,20 @@ module Threadify
18
18
  class Error < ::StandardError; end
19
19
  end
20
20
 
21
+ def Threadify(*args, &block)
22
+ # setup
23
+ #
24
+ opts = args.last.is_a?(Hash) ? args.pop : {}
25
+ opts.keys.each{|key| opts[key.to_s.to_sym] = opts.delete(key)}
26
+ opts[:threads] ||= (Numeric === args.first ? args.shift : Threadify.threads)
27
+ opts[:strategy] ||= (args.empty? ? Threadify.strategy : args)
28
+
29
+ threads = Integer(opts[:threads])
30
+
31
+ array_of_blocks = Array.new(threads){ block }
32
+ array_of_blocks.threadify(opts){|b| b.call()}
33
+ end
34
+
21
35
  module Enumerable
22
36
  def threadify(*args, &block)
23
37
  # setup
data/threadify.gemspec CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification::new do |spec|
5
5
  spec.name = "threadify"
6
- spec.version = "1.2.0"
6
+ spec.version = "1.3.0"
7
7
  spec.platform = Gem::Platform::RUBY
8
8
  spec.summary = "threadify"
9
9
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: threadify
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ara T. Howard
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-09 00:00:00 -06:00
12
+ date: 2009-09-10 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies: []
15
15