epitools 0.5.128 → 0.5.129

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
  SHA256:
3
- metadata.gz: 55db8684ff41f2465660f1b532823595eda3c5ffadcd15e43538c29a5ea5ef20
4
- data.tar.gz: e866e2ebc77c18506142528d9de6da16db99a03f31f1caed72960329439d2a8e
3
+ metadata.gz: 74b341f10e9697a2d9e93aad5aa91b7f799e75a3cd817d712bce3e15cd18428d
4
+ data.tar.gz: bce241006bd3b743410e3b6833145a5e72052637d7e918caa2562564b6ad4f5b
5
5
  SHA512:
6
- metadata.gz: 4d3c32dd1040271ae4eaf4e6d4a190d0d3518ceff7eb91a668ab243a306410460bc6336262e12f2d8db2b6e5f5ad87ae91c13e3eff23a2f31b4fb999b671cf29
7
- data.tar.gz: '086ea2d99290c419af5cecd34bcfd367517429bee37f2ff0a404178b8ae50f46ba2fd68b147f456bd0ea946b89665f592c463c47b4423f6d953d317b3cc5ea5f'
6
+ metadata.gz: ef8edebf3480e814c17e90f5c200fe1dc70a45827d8c2e52d2d7834291f61fb67824c5c5b6f869805f8751ea53d0eb95aa83e86daba42eb748d34ea66061ad6a
7
+ data.tar.gz: 38abf237811351f91306dd1d1e66e9104040645aa3ff743d13609a155853aa6ffa80b9967961edda5f20e1ad67068ffc298beafac47857210eca9ebb6a4ec87f
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.128
1
+ 0.5.129
@@ -65,19 +65,20 @@ autoload :IPAddr, 'ipaddr'
65
65
 
66
66
  ## Nonstandard library (epitools)
67
67
 
68
- autoload :Path, 'epitools/path'
69
- autoload :Ezdb, 'epitools/ezdb'
70
- autoload :Browser, 'epitools/browser'
71
- autoload :Rash, 'epitools/rash'
72
- autoload :Ratio, 'epitools/ratio'
73
- autoload :ProgressBar, 'epitools/progressbar'
74
- autoload :Trie, 'epitools/trie'
75
- autoload :MimeMagic, 'epitools/mimemagic'
76
- autoload :Term, 'epitools/term'
77
- autoload :Iter, 'epitools/iter'
78
- autoload :WM, 'epitools/wm'
79
- autoload :TypedStruct, 'epitools/typed_struct'
80
- autoload :Sys, 'epitools/sys'
68
+ autoload :Path, 'epitools/path'
69
+ autoload :Ezdb, 'epitools/ezdb'
70
+ autoload :Browser, 'epitools/browser'
71
+ autoload :Rash, 'epitools/rash'
72
+ autoload :Ratio, 'epitools/ratio'
73
+ autoload :ProgressBar, 'epitools/progressbar'
74
+ autoload :Trie, 'epitools/trie'
75
+ autoload :MimeMagic, 'epitools/mimemagic'
76
+ autoload :Term, 'epitools/term'
77
+ autoload :Iter, 'epitools/iter'
78
+ autoload :WM, 'epitools/wm'
79
+ autoload :TypedStruct, 'epitools/typed_struct'
80
+ autoload :Sys, 'epitools/sys'
81
+ autoload :JobRunner, 'epitools/job_runner'
81
82
  autoload :SemanticVersion, 'epitools/semantic_version'
82
83
 
83
84
  autoload :Matrix, 'epitools/core_ext/matrix'
@@ -87,7 +88,7 @@ autoreq(:Vector) { Matrix }
87
88
  module Epi
88
89
  autoload :Slop, 'epitools/slop'
89
90
  end
90
- autoreq(:Slop) do
91
+ autoreq(:Slop) do
91
92
  Slop = Epi::Slop
92
93
  end
93
94
 
@@ -0,0 +1,97 @@
1
+ #
2
+ # Runs many jobs in parallel, and returns their interleaved results.
3
+ # (NOTE: The JobRunner can be run multiple times; each time the blocks
4
+ # will be executed again.)
5
+ #
6
+ # Examples:
7
+ #
8
+ # JobRunner.new do |jr|
9
+ # jr.add { 3 }
10
+ # jr.add { sleep 0.1; 2 }
11
+ # jr.add { sleep 0.2; 1 }
12
+ #
13
+ # jr.each_result do |result|
14
+ # p result
15
+ # end
16
+ # end
17
+ #
18
+ # jr = JobRunner.new(
19
+ # proc { 1 },
20
+ # proc { 2 },
21
+ # proc { 3 }
22
+ # )
23
+ #
24
+ # 2.times do
25
+ # jr.each_result { |result| p result }
26
+ # end
27
+ #
28
+ class JobRunner
29
+ def initialize(*blocks)
30
+ @threads = []
31
+ @results = Thread::Queue.new
32
+ @jobs = []
33
+ @started = false
34
+
35
+ if blocks.any?
36
+ blocks.each { |block| add &block }
37
+ else
38
+ yield self if block_given?
39
+ end
40
+ end
41
+
42
+ def add(&block)
43
+ @jobs << block
44
+ end
45
+
46
+ def reap!
47
+ @threads.delete_if { |t| not t.alive? } if @threads.any?
48
+ end
49
+
50
+ def go!
51
+ raise "Error: already started" if @started
52
+ @started = true
53
+ @jobs.each do |job|
54
+ @threads << Thread.new do
55
+ @results << job.call
56
+ end
57
+ end
58
+ end
59
+
60
+ def each_result
61
+ go! unless @started
62
+
63
+ loop do
64
+ yield @results.pop
65
+ reap!
66
+ break if @threads.empty? and @results.empty?
67
+ end
68
+
69
+ @started = false
70
+ end
71
+ end
72
+
73
+
74
+ if __FILE__ == $0
75
+ JobRunner.new do |jr|
76
+ jr.add { 3 }
77
+ jr.add { sleep 0.1; 2 }
78
+ jr.add { sleep 0.2; 1 }
79
+
80
+ jr.each_result do |result|
81
+ p result
82
+ end
83
+ end
84
+
85
+ puts
86
+
87
+ jr = JobRunner.new(
88
+ proc { 1 },
89
+ proc { 2 },
90
+ proc { 3 }
91
+ )
92
+
93
+ 2.times do
94
+ jr.each_result { |r| p r }
95
+ puts
96
+ end
97
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epitools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.128
4
+ version: 0.5.129
5
5
  platform: ruby
6
6
  authors:
7
7
  - epitron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-22 00:00:00.000000000 Z
11
+ date: 2020-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -72,6 +72,7 @@ files:
72
72
  - lib/epitools/hexdump.rb
73
73
  - lib/epitools/iter.rb
74
74
  - lib/epitools/its.rb
75
+ - lib/epitools/job_runner.rb
75
76
  - lib/epitools/lcs.rb
76
77
  - lib/epitools/mimemagic.rb
77
78
  - lib/epitools/mimemagic_tables.rb