threadify_procs 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 68ea99f978e760abe63d79a225b5a62ba609d58a
4
- data.tar.gz: 65b85ee7bbe065f5ef827c76fd44c93886237a6e
3
+ metadata.gz: e93753cbd4cee81858812b8d2fbbbf56385441a9
4
+ data.tar.gz: 7028781f3c82a9dc738b8c52e2140ae5c7be1d8e
5
5
  SHA512:
6
- metadata.gz: f4780d7d718692e686c93e508dec9d0bdad3c7b775f5d912b82b4a38e068b07187f9d819d05f29dbf88b2d0d554968de0df4775db6ed5889140893efd8f64eb5
7
- data.tar.gz: 84b1e44be3f747f6ddb22676d77456481878d93f68b33a1f8d3e8f907a713e61c7ae1c4a36881275c01765bb0db9a699e31f76d1679476953ecd10197e3e900f
6
+ metadata.gz: c80d1302ade2493c008bd7c060e57a9abdc0d31a8c8857c0883964b4cb54b1d19c9e46c75d0ea4c43f0ec905b188dfe837c27606298d551f3117666e1ca33de4
7
+ data.tar.gz: 90ec402b115ec1a5755278b3ffb8527e5915cb8d8f7beabf774f06ec4be172d6867d956b4fb001753337c354227fe0124d3fc9d0d29eb37bfae981cec2497cd1
@@ -1,3 +1,3 @@
1
1
  module ThreadifyProcs
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: threadify_procs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antoine Qu'hen