stagnum 0.9.0 → 1.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d935b2dcef0e06bf324569727b0e0416444d733d20da884426bd28d5d76ea18
4
- data.tar.gz: f00a9639d70ba8c6fbd3da0e0877e4c8bbff5ae8968a1691d5312644f230e4b4
3
+ metadata.gz: e0cac0775cf6ecc7f093c11d1e7d0b5a5cc1684ec54c2d6437343206a4428737
4
+ data.tar.gz: 87a83019e96db408649034b01ddae9be7e1061ae27d68bdc5b0cd5cea0d1c58c
5
5
  SHA512:
6
- metadata.gz: '08c53834df95715abd1b77ab151ff49d29b9913db15cb81903c18174e67e0a2d4b33fecd45697efdfb4574bb732b0cb840b2d438ac9def2bae70e448b41eeea9'
7
- data.tar.gz: ce0f53b3c4650e5aa3d2e1880a4fe31a49162949881f1fa755c70e7b9aed8979669e3044027aff6297515c19f33139a6c7b2cc7ebaa055898226b80e983c12ce
6
+ metadata.gz: ec87441d4d3ed2cb15da9b41fccb4fee7cece403e52159acff0f16cc43f54ebafcf280a38a418b83f9e49f62ba55c6664c981ee1042bce2caf19cd7a83a81f0c
7
+ data.tar.gz: c9cc2a5b4f35eac7c4be651c65182631b4c550e61389d6ec44a33700be2f951256d8e0661275c7ba206858dfa1e54decd7bf7598c46e879ee1fce5ce326f068e
data/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+
2
+ # CHANGELOG.md
3
+
4
+
5
+ ## stagnum 1.0.0 released 2025-03-05
6
+
7
+ * Stagnum::DoneQueue.on_(success|failure|pop)
8
+
9
+
10
+ ## stagnum 0.9.0 released 2025-03-04
11
+
12
+ * Initial release
13
+
data/README.md CHANGED
@@ -45,6 +45,32 @@ pp successes
45
45
 
46
46
  One can use `Thread::Queue` instead of `Stagnum::DoneQueue`
47
47
 
48
+ `Stagnum::DoneQueue` also has `#on_success` and `#on_failure` methods:
49
+
50
+ ```ruby
51
+ pool = Stagnum::Pool.new('pool-zero', 4)
52
+
53
+ s, f = [], []
54
+
55
+ q = Stagnum::DoneQueue.new
56
+ q.on_success do |r|
57
+ s << r
58
+ end
59
+ q.on_failure do |r|
60
+ f << r
61
+ end
62
+
63
+ 30.times do |i|
64
+
65
+ pool.enqueue(q, { i: i }) do |d|
66
+ sleep rand * 1
67
+ d[:tname] = Thread.current.name
68
+ end
69
+ end
70
+
71
+ q.pop_all
72
+ ```
73
+
48
74
  ## LICENSE
49
75
 
50
76
  MIT, see [LICENSE.txt](LICENSE.txt)
data/lib/stagnum.rb CHANGED
@@ -5,8 +5,7 @@ require 'thread'
5
5
 
6
6
  module Stagnum
7
7
 
8
- VERSION = '0.9.0'
9
-
8
+ VERSION = '1.0.0'.freeze
10
9
 
11
10
  class Pool
12
11
 
@@ -57,12 +56,13 @@ module Stagnum
57
56
 
58
57
  class DoneQueue < ::Thread::Queue
59
58
 
60
- attr_reader :count
59
+ attr_reader :listeners, :count
61
60
 
62
61
  def initialize(items=[])
63
62
 
64
63
  super
65
64
 
65
+ @listeners = []
66
66
  @count = 0
67
67
  end
68
68
 
@@ -77,20 +77,36 @@ module Stagnum
77
77
 
78
78
  @count.times
79
79
  .inject([ [], [] ]) { |a, i|
80
- r = self.pop
80
+ r = pop
81
81
  a[r[0] == :success ? 0 : 1] << r
82
82
  a }
83
83
  end
84
+
85
+ def pop(non_blocking=false)
86
+
87
+ r = super
88
+
89
+ @listeners.each do |l|
90
+ l0 = l[0]
91
+ l[1].call(r) if l0 == :any || l0 == r[0]
92
+ end if r.is_a?(Array)
93
+
94
+ r
95
+ end
96
+
97
+ def on_success(&block); @listeners << [ :success, block ]; end
98
+ def on_failure(&block); @listeners << [ :failure, block ]; end
99
+ def on_pop(&block); @listeners << [ :any, block ]; end
84
100
  end
85
101
 
86
102
  class WorkerThread < ::Thread
87
103
 
88
- def initialize(stagnum, work_queue)
104
+ def initialize(pool, work_queue)
89
105
 
90
- @stagnum = stagnum
106
+ @pool = pool
91
107
  @work_queue = work_queue
92
108
 
93
- self.name = "#{stagnum.name}__#{stagnum.next_worker_thread_id}"
109
+ self.name = "#{pool.name}__#{pool.next_worker_thread_id}"
94
110
 
95
111
  super do
96
112
 
data/stagnum.gemspec CHANGED
@@ -12,10 +12,10 @@ Gem::Specification.new do |s|
12
12
  s.email = [ 'jmettraux+flor@gmail.com' ]
13
13
  s.homepage = 'https://github.com/floraison/stagnum'
14
14
  s.license = 'MIT'
15
- s.summary = 'a worker pool'
15
+ s.summary = 'a work thread pool'
16
16
 
17
17
  s.description = %{
18
- A stupid worker pool
18
+ A stupid work thread pool
19
19
  }.strip
20
20
 
21
21
  s.metadata = {
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stagnum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-03-04 00:00:00.000000000 Z
10
+ date: 2025-03-05 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: probatio
@@ -23,13 +23,14 @@ dependencies:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
25
  version: '1.0'
26
- description: A stupid worker pool
26
+ description: A stupid work thread pool
27
27
  email:
28
28
  - jmettraux+flor@gmail.com
29
29
  executables: []
30
30
  extensions: []
31
31
  extra_rdoc_files: []
32
32
  files:
33
+ - CHANGELOG.md
33
34
  - LICENSE.txt
34
35
  - README.md
35
36
  - lib/stagnum.rb
@@ -60,5 +61,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
61
  requirements: []
61
62
  rubygems_version: 3.6.2
62
63
  specification_version: 4
63
- summary: a worker pool
64
+ summary: a work thread pool
64
65
  test_files: []