threadify_procs 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/lib/threadify_procs/version.rb +1 -1
- data/lib/threadify_procs.rb +5 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e93753cbd4cee81858812b8d2fbbbf56385441a9
|
4
|
+
data.tar.gz: 7028781f3c82a9dc738b8c52e2140ae5c7be1d8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c80d1302ade2493c008bd7c060e57a9abdc0d31a8c8857c0883964b4cb54b1d19c9e46c75d0ea4c43f0ec905b188dfe837c27606298d551f3117666e1ca33de4
|
7
|
+
data.tar.gz: 90ec402b115ec1a5755278b3ffb8527e5915cb8d8f7beabf774f06ec4be172d6867d956b4fb001753337c354227fe0124d3fc9d0d29eb37bfae981cec2497cd1
|
data/lib/threadify_procs.rb
CHANGED
@@ -4,6 +4,7 @@ module ThreadifyProcs
|
|
4
4
|
|
5
5
|
def call_with_threads procs, options={}
|
6
6
|
set_procs procs
|
7
|
+
return if procs.blank?
|
7
8
|
set_options options
|
8
9
|
with_writer_thread do
|
9
10
|
launch_procs
|
@@ -50,10 +51,10 @@ module ThreadifyProcs
|
|
50
51
|
end
|
51
52
|
|
52
53
|
def set_procs procs
|
53
|
-
@procs = procs
|
54
54
|
unless procs.kind_of?(Array) && procs.all?{|_proc|_proc.kind_of?(Proc)}
|
55
55
|
raise 'ThreadifyProcs expects an array of procs.'
|
56
56
|
end
|
57
|
+
@procs = procs
|
57
58
|
end
|
58
59
|
|
59
60
|
def set_options options
|
@@ -61,9 +62,8 @@ module ThreadifyProcs
|
|
61
62
|
if @number_of_threads < 1
|
62
63
|
raise 'ThreadifyProcs expects a positive number of Threads.'
|
63
64
|
end
|
64
|
-
@procs_per_thread = (procs.size / @number_of_threads).ceil
|
65
|
+
@procs_per_thread = (@procs.size / @number_of_threads.to_f).ceil
|
65
66
|
@with_writer = !!options[:with_writer]
|
66
|
-
@files_to_write = [] if @with_writer
|
67
67
|
end
|
68
68
|
|
69
69
|
def with_writer_thread
|
@@ -80,6 +80,8 @@ module ThreadifyProcs
|
|
80
80
|
while !@procs.empty? do
|
81
81
|
groups << @procs.shift(@procs_per_thread)
|
82
82
|
end
|
83
|
+
puts "#{groups.size} Threads created, "\
|
84
|
+
"number of procs in each ~#{groups.map(&:size).sum.to_f / groups.size}."
|
83
85
|
end
|
84
86
|
end
|
85
87
|
|