always 0.2.0 → 0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 25308b6e2214b17ef2c68e68ebf2bb160c78d9667c9e5cffe79e46ac8971a10c
4
- data.tar.gz: 8379f28c2d992d0376755b4da3e9445865adbd73f57719aa2019b2e96900a8e8
3
+ metadata.gz: 51f44aa92893e18ed128a1e9b701e9da258afa730ff1455a01610e570426672d
4
+ data.tar.gz: 4d4b568c045f1a5e625b6a06fb2d9663992e95e2b4dd00033af272aec8f01192
5
5
  SHA512:
6
- metadata.gz: b1b4b18ed1122fc6bc1c58a40f5776b437c0369b1c4abc2b02e9340bbd90bdf3e48dd0abf2182e55137afd6c8754aa9c63d0aee663cb694798c9e61dcaea991c
7
- data.tar.gz: 30ecc3f6460995ed225cd91ca2e7294226a30abcacded97828e025631f93f88902b672b463566756760acf1db21391f0735759568790417e5e226a4f32768d0e
6
+ metadata.gz: 2cf17c1132d00c1638160556afee332f100fc29ccb19a5f7f001a1dc4558edfea665ee8540b558fbe7cafc043d3c03d64272cbeff9a753970560c55292520952
7
+ data.tar.gz: 5c8483e2de654215d6a63967e8cce0140e0db2ada2298e53713320d5e98a4481975258dae6c08fd897465e772682d3a61e2ac6aeabe885568a2dda772850d651
data/Gemfile CHANGED
@@ -1,18 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
3
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2026 Yegor Bugayenko
4
4
  # SPDX-License-Identifier: MIT
5
5
 
6
6
  source 'https://rubygems.org'
7
7
  gemspec
8
8
 
9
- gem 'minitest', '~>5.25', require: false
9
+ gem 'minitest', '~>6.0', require: false
10
10
  gem 'minitest-reporters', '~>1.7', require: false
11
11
  gem 'rake', '~>13.2', require: false
12
12
  gem 'rubocop', '~>1.64', require: false
13
+ gem 'rubocop-elegant', '~>0.5', require: false
13
14
  gem 'rubocop-minitest', '~>0.38', require: false
14
15
  gem 'rubocop-performance', '~>1.25', require: false
15
16
  gem 'rubocop-rake', '~>0.7', require: false
16
- gem 'simplecov', '~>0.22', require: false
17
- gem 'simplecov-cobertura', '~>3.0', require: false
17
+ gem 'simplecov', '~>1.0', require: false
18
+ gem 'simplecov-cobertura', '~>4.0', require: false
18
19
  gem 'yard', '~>0.9', require: false
data/Gemfile.lock CHANGED
@@ -7,69 +7,79 @@ PATH
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- ansi (1.5.0)
10
+ ansi (1.6.1)
11
+ logger
11
12
  ast (2.4.3)
12
13
  builder (3.3.0)
13
- concurrent-ruby (1.3.5)
14
- docile (1.4.1)
15
- json (2.15.2)
16
- language_server-protocol (3.17.0.5)
14
+ concurrent-ruby (1.3.8)
15
+ drb (2.2.3)
16
+ json (3.2.0)
17
+ language_server-protocol (3.17.0.6)
17
18
  lint_roller (1.1.0)
18
- minitest (5.26.0)
19
- minitest-reporters (1.7.1)
19
+ logger (1.7.0)
20
+ minitest (6.1.0)
21
+ drb (~> 2.0)
22
+ prism (>= 1.5, < 3)
23
+ minitest-reporters (1.8.0)
20
24
  ansi
21
25
  builder
22
- minitest (>= 5.0)
26
+ minitest (>= 5.0, < 7)
23
27
  ruby-progressbar
24
- parallel (1.27.0)
25
- parser (3.3.10.0)
28
+ parallel (2.3.0)
29
+ parser (3.3.14.0)
26
30
  ast (~> 2.4.1)
27
31
  racc
28
- prism (1.6.0)
32
+ prism (2.1.0)
33
+ prism (2.1.0-aarch64-linux-gnu)
34
+ prism (2.1.0-arm-linux-gnu)
35
+ prism (2.1.0-arm64-darwin)
36
+ prism (2.1.0-x64-mingw-ucrt)
37
+ prism (2.1.0-x86_64-darwin)
38
+ prism (2.1.0-x86_64-linux-gnu)
29
39
  racc (1.8.1)
30
40
  rainbow (3.1.1)
31
- rake (13.3.0)
32
- regexp_parser (2.11.3)
41
+ rake (13.4.2)
42
+ regexp_parser (2.13.4)
33
43
  rexml (3.4.4)
34
- rubocop (1.81.6)
35
- json (~> 2.3)
44
+ rubocop (1.93.0)
45
+ json (>= 2.3)
36
46
  language_server-protocol (~> 3.17.0.2)
37
47
  lint_roller (~> 1.1.0)
38
- parallel (~> 1.10)
48
+ parallel (>= 1.10)
39
49
  parser (>= 3.3.0.2)
40
50
  rainbow (>= 2.2.2, < 4.0)
41
- regexp_parser (>= 2.9.3, < 3.0)
42
- rubocop-ast (>= 1.47.1, < 2.0)
51
+ regexp_parser (>= 2.11.3, < 3.0)
52
+ rubocop-ast (>= 1.54.0, < 2.0)
43
53
  ruby-progressbar (~> 1.7)
44
54
  unicode-display_width (>= 2.4.0, < 4.0)
45
- rubocop-ast (1.47.1)
55
+ rubocop-ast (1.54.0)
56
+ ast (~> 2.4)
46
57
  parser (>= 3.3.7.2)
47
- prism (~> 1.4)
48
- rubocop-minitest (0.38.2)
58
+ prism (>= 1.7)
59
+ racc
60
+ rubocop-elegant (0.8.0)
61
+ lint_roller (~> 1.1)
62
+ rubocop (~> 1.75)
63
+ rubocop-minitest (0.41.0)
49
64
  lint_roller (~> 1.1)
50
- rubocop (>= 1.75.0, < 2.0)
65
+ rubocop (>= 1.89.0, < 2.0)
51
66
  rubocop-ast (>= 1.38.0, < 2.0)
52
- rubocop-performance (1.26.1)
67
+ rubocop-performance (1.27.0)
53
68
  lint_roller (~> 1.1)
54
- rubocop (>= 1.75.0, < 2.0)
69
+ rubocop (>= 1.89.0, < 2.0)
55
70
  rubocop-ast (>= 1.47.1, < 2.0)
56
71
  rubocop-rake (0.7.1)
57
72
  lint_roller (~> 1.1)
58
73
  rubocop (>= 1.72.1)
59
74
  ruby-progressbar (1.13.0)
60
- simplecov (0.22.0)
61
- docile (~> 1.1)
62
- simplecov-html (~> 0.11)
63
- simplecov_json_formatter (~> 0.1)
64
- simplecov-cobertura (3.1.0)
75
+ simplecov (1.3.2)
76
+ simplecov-cobertura (4.0.0)
65
77
  rexml
66
- simplecov (~> 0.19)
67
- simplecov-html (0.13.2)
68
- simplecov_json_formatter (0.1.4)
69
- unicode-display_width (3.2.0)
70
- unicode-emoji (~> 4.1)
71
- unicode-emoji (4.1.0)
72
- yard (0.9.37)
78
+ simplecov (~> 1.0)
79
+ unicode-display_width (3.3.0)
80
+ unicode-emoji (~> 4.3)
81
+ unicode-emoji (4.3.0)
82
+ yard (0.9.46)
73
83
 
74
84
  PLATFORMS
75
85
  aarch64-linux
@@ -83,15 +93,16 @@ PLATFORMS
83
93
 
84
94
  DEPENDENCIES
85
95
  always!
86
- minitest (~> 5.25)
96
+ minitest (~> 6.0)
87
97
  minitest-reporters (~> 1.7)
88
98
  rake (~> 13.2)
89
99
  rubocop (~> 1.64)
100
+ rubocop-elegant (~> 0.5)
90
101
  rubocop-minitest (~> 0.38)
91
102
  rubocop-performance (~> 1.25)
92
103
  rubocop-rake (~> 0.7)
93
- simplecov (~> 0.22)
94
- simplecov-cobertura (~> 3.0)
104
+ simplecov (~> 1.0)
105
+ simplecov-cobertura (~> 4.0)
95
106
  yard (~> 0.9)
96
107
 
97
108
  BUNDLED WITH
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2024-2025 Yegor Bugayenko
3
+ Copyright (c) 2024-2026 Yegor Bugayenko
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the 'Software'), to deal
data/LICENSES/MIT.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2024-2025 Yegor Bugayenko
3
+ Copyright (c) 2024-2026 Yegor Bugayenko
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the 'Software'), to deal
data/README.md CHANGED
@@ -19,7 +19,7 @@ require 'always'
19
19
  a = Always.new(5) do
20
20
  puts "I'm alive"
21
21
  end
22
- # Start them all together spinning forever with 30-seconds delay between cycles:
22
+ # Start them all together spinning forever with a 30-second delay between cycles:
23
23
  a.start!(30)
24
24
  # Stop them all together:
25
25
  a.stop!
data/Rakefile CHANGED
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
3
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2026 Yegor Bugayenko
4
4
  # SPDX-License-Identifier: MIT
5
5
 
6
- require 'rubygems'
7
6
  require 'rake'
8
7
  require 'rake/clean'
8
+ require 'rubygems'
9
9
 
10
10
  def name
11
11
  @name ||= File.basename(Dir['*.gemspec'].first, '.*')
@@ -31,6 +31,7 @@ require 'yard'
31
31
  desc 'Build Yard documentation'
32
32
  YARD::Rake::YardocTask.new do |t|
33
33
  t.files = ['lib/**/*.rb']
34
+ t.options = ['--fail-on-warning']
34
35
  end
35
36
 
36
37
  require 'rubocop/rake_task'
data/always.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
3
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2026 Yegor Bugayenko
4
4
  # SPDX-License-Identifier: MIT
5
5
 
6
6
  require 'English'
7
7
 
8
8
  Gem::Specification.new do |s|
9
- s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
9
+ s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to?(:required_rubygems_version=)
10
10
  s.required_ruby_version = '>=3.2'
11
11
  s.name = 'always'
12
- s.version = '0.2.0'
12
+ s.version = '0.3.0'
13
13
  s.license = 'MIT'
14
14
  s.summary = 'A simple Ruby framework that spins a loop forever, in a background thread'
15
15
  s.description =
@@ -23,6 +23,6 @@ Gem::Specification.new do |s|
23
23
  s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
24
24
  s.rdoc_options = ['--charset=UTF-8']
25
25
  s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
26
- s.add_dependency 'concurrent-ruby', '~>1.1'
26
+ s.add_dependency('concurrent-ruby', '~>1.1')
27
27
  s.metadata['rubygems_mfa_required'] = 'true'
28
28
  end
data/lib/always.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
3
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2026 Yegor Bugayenko
4
4
  # SPDX-License-Identifier: MIT
5
5
 
6
6
  require 'concurrent/atom'
@@ -9,7 +9,7 @@ require 'securerandom'
9
9
  # Always.
10
10
  #
11
11
  # In order to start five threads performing the same piece of code
12
- # over and over again, with a 60-seconds pause between cycles, do this:
12
+ # over and over again, with a 60-second pause between cycles, do this:
13
13
  #
14
14
  # require 'always'
15
15
  # a = Always.new(5) do
@@ -27,28 +27,19 @@ require 'securerandom'
27
27
  # so far, and +E+ is the total number of all errors seen so far.
28
28
  #
29
29
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
30
- # Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
30
+ # Copyright:: Copyright (c) 2024-2026 Yegor Bugayenko
31
31
  # License:: MIT
32
32
  class Always
33
- # Get the array of most recent exception backtraces.
34
- # @return [Array<Exception>] The array of exceptions caught
35
- # @example
36
- # a = Always.new(5, max_backtraces: 10)
37
- # a.start { raise 'Oops' }
38
- # sleep 1
39
- # puts a.backtraces.size # => number of exceptions caught
40
33
  attr_reader :backtraces
41
34
 
42
- # The version of the framework.
43
- VERSION = '0.2.0'
35
+ VERSION = '0.3.0'
44
36
 
45
37
  # Constructor.
46
38
  # @param [Integer] total The number of threads to run
47
39
  # @param [Integer] max_backtraces How many backtraces to keep in memory?
48
40
  # @param [Block] block The block to execute
49
41
  def initialize(total, max_backtraces: 32, name: "always-#{SecureRandom.hex(4)}", &block)
50
- raise "The number of threads (#{total}) must be positive" unless total.positive?
51
-
42
+ raise(ArgumentError, "The number of threads (#{total}) must be positive") unless total.positive?
52
43
  @total = total
53
44
  @block = block
54
45
  @on_error = nil
@@ -81,12 +72,11 @@ class Always
81
72
  # Start them all and let them run forever (until the +stop+ method is called).
82
73
  # @param [Integer] pause The delay between cycles, in seconds
83
74
  def start!(pause = 0)
84
- raise 'It is running now, call .stop() first' unless @threads.empty?
85
-
75
+ raise(StandardError, 'It is running now, call .stop() first') unless @threads.empty?
86
76
  (0..(@total - 1)).each do |i|
87
77
  t =
88
78
  Thread.new do
89
- body(pause)
79
+ body(pause, i)
90
80
  end
91
81
  t.name = "#{@name}-#{i + 1}"
92
82
  @threads[i] = t
@@ -95,8 +85,7 @@ class Always
95
85
 
96
86
  # Stop them all.
97
87
  def stop!
98
- raise 'It is not running now, call .start() first' if @threads.empty?
99
-
88
+ raise(StandardError, 'It is not running now, call .start() first') if @threads.empty?
100
89
  @threads.delete_if do |t|
101
90
  t.kill
102
91
  sleep(0.001) while t.alive?
@@ -109,7 +98,7 @@ class Always
109
98
  # Represent its internal state as a string.
110
99
  # @return [String] Something like "4/230/23", where 4 is the number of running
111
100
  # threads, 230 is the number of successful loops, and 23 is the number
112
- # of failures occurred so far.
101
+ # of failures that occurred so far.
113
102
  # @example
114
103
  # a = Always.new(5)
115
104
  # a.start(60) { puts 'Working...' }
@@ -120,28 +109,28 @@ class Always
120
109
 
121
110
  private
122
111
 
123
- # rubocop:disable Lint/RescueException
124
- def body(pause)
112
+ # rubocop:disable-next Lint/RescueException
113
+ def body(pause, idx = 0)
125
114
  loop do
126
- one
115
+ one(idx)
127
116
  @cycles.swap { |c| c + 1 }
128
117
  sleep(pause) unless pause.zero?
129
118
  rescue Exception
130
- # If we reach this point, we must not even try to
131
- # do anything. Here we must quietly ignore everything
132
- # and let the daemon go to the next cycle.
119
+ nil
133
120
  end
134
121
  end
135
- # rubocop:enable Lint/RescueException
136
122
 
137
- # rubocop:disable Lint/RescueException
138
- def one
123
+ # rubocop:disable-next Lint/RescueException
124
+ def one(idx = 0)
139
125
  @block.call
140
126
  rescue Exception => e
141
127
  @errors.swap { |c| c + 1 }
142
128
  @backtraces << e
143
129
  @backtraces.shift if @backtraces.size > @max_backtraces
144
- @on_error&.call(e, Thread.current.object_id)
130
+ begin
131
+ @on_error&.call(e, idx + 1)
132
+ rescue Exception
133
+ nil
134
+ end
145
135
  end
146
- # rubocop:enable Lint/RescueException
147
136
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: always
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko