Skip to content

Commit 10f3695

Browse files
committed
Modernize code.
1 parent b3764e6 commit 10f3695

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+302
-250
lines changed

.mailmap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ Leon Löchner <leonloechner@gmx.de> <60091705+leonnicolas@users.noreply.github.c
88
Math Ieu <sigsys@gmail.com>
99
Shopify Inc. <samuel.williams@shopify.com>
1010
Shigeru Nakajima <shigeru.nakajima@gmail.com>
11+
Yuhi Sato <yuhi120101@gmail.com>

.rubocop.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
plugins:
2+
- rubocop-md
23
- rubocop-socketry
34

45
AllCops:
56
DisabledByDefault: true
67

8+
# Socketry specific rules:
9+
710
Layout/ConsistentBlankLineIndentation:
811
Enabled: true
912

13+
Layout/BlockDelimiterSpacing:
14+
Enabled: true
15+
16+
Style/GlobalExceptionVariables:
17+
Enabled: true
18+
19+
# General Layout rules:
20+
1021
Layout/IndentationStyle:
1122
Enabled: true
1223
EnforcedStyle: tabs
@@ -33,6 +44,9 @@ Layout/BeginEndAlignment:
3344
Enabled: true
3445
EnforcedStyleAlignWith: start_of_line
3546

47+
Layout/RescueEnsureAlignment:
48+
Enabled: true
49+
3650
Layout/ElseAlignment:
3751
Enabled: true
3852

@@ -41,10 +55,15 @@ Layout/DefEndAlignment:
4155

4256
Layout/CaseIndentation:
4357
Enabled: true
58+
EnforcedStyle: end
4459

4560
Layout/CommentIndentation:
4661
Enabled: true
4762

63+
Layout/FirstHashElementIndentation:
64+
Enabled: true
65+
EnforcedStyle: consistent
66+
4867
Layout/EmptyLinesAroundClassBody:
4968
Enabled: true
5069

async.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
77
spec.version = Async::VERSION
88

99
spec.summary = "A concurrency framework for Ruby."
10-
spec.authors = ["Samuel Williams", "Shopify Inc.", "Bruno Sutic", "Jeremy Jung", "Olle Jonsson", "Patrik Wenger", "Devin Christensen", "Emil Tin", "Jamie McCarthy", "Kent Gruber", "Alan Wu", "Brian Morearty", "Colin Kelley", "Dimitar Peychinov", "Gert Goet", "Jahfer Husain", "Jatin Goyal", "Jiang Jinyang", "Josh Teeter", "Julien Portalier", "Jun Jiang", "Ken Muryoi", "Leon Löchner", "Mark Montroy", "Masafumi Okura", "Masayuki Yamamoto", "Math Ieu", "Ryan Musgrave", "Salim Semaoune", "Shannon Skipper", "Shigeru Nakajima", "Sokolov Yura", "Stefan Wrobel", "Trevor Turk"]
10+
spec.authors = ["Samuel Williams", "Shopify Inc.", "Bruno Sutic", "Jeremy Jung", "Olle Jonsson", "Patrik Wenger", "Devin Christensen", "Emil Tin", "Jamie McCarthy", "Kent Gruber", "Alan Wu", "Brian Morearty", "Colin Kelley", "Dimitar Peychinov", "Gert Goet", "Jahfer Husain", "Jatin Goyal", "Jiang Jinyang", "Josh Teeter", "Julien Portalier", "Jun Jiang", "Ken Muryoi", "Leon Löchner", "Mark Montroy", "Masafumi Okura", "Masayuki Yamamoto", "Math Ieu", "Ryan Musgrave", "Salim Semaoune", "Shannon Skipper", "Shigeru Nakajima", "Sokolov Yura", "Stefan Wrobel", "Trevor Turk", "Yuhi Sato"]
1111
spec.license = "MIT"
1212

1313
spec.cert_chain = ["release.cert"]

benchmark/condition.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,15 @@
128128

129129
Async do |task|
130130
# Check empty state
131-
100.times {test_condition.empty?}
131+
100.times{test_condition.empty?}
132132

133133
# Create a waiter
134134
waiter = task.async do
135135
test_condition.wait
136136
end
137137

138138
# Check waiting state
139-
100.times {test_condition.waiting?}
139+
100.times{test_condition.waiting?}
140140

141141
# Signal to complete
142142
test_condition.signal("done")
@@ -188,7 +188,7 @@
188188
# Producer
189189
producer = task.async do
190190
ready_condition.wait # Wait for consumer to be ready
191-
50.times {|i| "item-#{i}"} # Simulate work
191+
50.times{|i| "item-#{i}"} # Simulate work
192192
done_condition.signal("finished")
193193
end
194194

@@ -211,7 +211,7 @@
211211
test_condition = Async::Condition.new
212212

213213
Async do |task|
214-
waiter = task.async {test_condition.wait}
214+
waiter = task.async{test_condition.wait}
215215

216216
test_condition.signal("cleanup")
217217
waiter.wait

benchmark/queue.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
repeats.times do
2929
Async do
3030
# Create a batch of 100 items each time
31-
items = Array.new(100) {|i| "item-#{i}"}
31+
items = Array.new(100){|i| "item-#{i}"}
3232
queue.enqueue(*items)
3333
# Clear queue for next iteration
34-
100.times {queue.dequeue}
34+
100.times{queue.dequeue}
3535
end
3636
end
3737
end
@@ -40,7 +40,7 @@
4040
repeats.times do
4141
Async do
4242
# Pre-populate queue with 100 items
43-
items = Array.new(100) {|i| "item-#{i}"}
43+
items = Array.new(100){|i| "item-#{i}"}
4444
queue.enqueue(*items)
4545

4646
# Measure dequeue operations
@@ -119,7 +119,7 @@
119119
queue.push("item-#{i}")
120120
end
121121
# Signal completion to all consumers
122-
num_consumers.times {queue.push(nil)}
122+
num_consumers.times{queue.push(nil)}
123123
end
124124

125125
# Multiple consumers
@@ -145,7 +145,7 @@
145145
repeats.times do
146146
Async do |task|
147147
# Pre-populate with some items
148-
100.times {|i| queue.push("item-#{i}")}
148+
100.times{|i| queue.push("item-#{i}")}
149149

150150
# Check state frequently
151151
size_checker = task.async do
@@ -166,7 +166,7 @@
166166
[size_checker, modifier].each(&:wait)
167167

168168
# Clean up
169-
queue.size.times {queue.dequeue}
169+
queue.size.times{queue.dequeue}
170170
end
171171
end
172172
end
@@ -178,7 +178,7 @@
178178

179179
Async do
180180
# Fill queue
181-
50.times {|i| test_queue.push("item-#{i}")}
181+
50.times{|i| test_queue.push("item-#{i}")}
182182

183183
# Close it
184184
test_queue.close
@@ -197,16 +197,16 @@
197197
repeats.times do
198198
Async do
199199
# Fill the queue
200-
100.times {|i| queue.push("item-#{i}")}
200+
100.times{|i| queue.push("item-#{i}")}
201201

202202
# Empty the queue
203-
100.times {queue.dequeue}
203+
100.times{queue.dequeue}
204204

205205
# Fill again to test reuse
206-
100.times {|i| queue.push("item-#{i}")}
206+
100.times{|i| queue.push("item-#{i}")}
207207

208208
# Empty again
209-
100.times {queue.dequeue}
209+
100.times{queue.dequeue}
210210
end
211211
end
212212
end

benchmark/rubies/benchmark.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def write(buffer)
194194
workers.push f
195195
end
196196

197-
workers.each {|f| f.resume}
197+
workers.each{|f| f.resume}
198198

199199
master_fiber = Fiber.new do
200200
NUM_WORKERS.times do |worker_num|

benchmark/task.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
measure "simple task creation and completion" do |repeats|
1616
Async do |task|
1717
repeats.times do
18-
child = task.async {"result"}
18+
child = task.async{"result"}
1919
child.wait
2020
end
2121
end
@@ -51,7 +51,7 @@
5151
measure "wait on immediately completing tasks" do |repeats|
5252
Async do |task|
5353
repeats.times do
54-
child = task.async {"result"}
54+
child = task.async{"result"}
5555
child.wait
5656
end
5757
end
@@ -74,7 +74,7 @@
7474
completed_tasks = []
7575
Async do |task|
7676
100.times do
77-
completed_tasks << task.async {"completed"}
77+
completed_tasks << task.async{"completed"}
7878
end
7979

8080
# Wait for all to complete

benchmark/timers/after_0.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# frozen_string_literal: true
33

44
# Released under the MIT License.
5-
# Copyright, 2024, by Samuel Williams.
5+
# Copyright, 2024-2025, by Samuel Williams.
66

77
require "benchmark/ips"
88

@@ -17,7 +17,7 @@
1717
timers = Timers::Group.new
1818

1919
while count > 0
20-
timers.after(0) {count -= 1}
20+
timers.after(0){count -= 1}
2121
timers.fire
2222
end
2323
end
@@ -26,7 +26,7 @@
2626
timers = IO::Event::Timers.new
2727

2828
while count > 0
29-
timers.after(0) {count -= 1}
29+
timers.after(0){count -= 1}
3030
timers.fire
3131
end
3232
end

benchmark/timers/after_cancel.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# frozen_string_literal: true
33

44
# Released under the MIT License.
5-
# Copyright, 2024, by Samuel Williams.
5+
# Copyright, 2024-2025, by Samuel Williams.
66

77
require "benchmark/ips"
88

@@ -17,7 +17,7 @@
1717
timers = Timers::Group.new
1818

1919
while count > 0
20-
timer = timers.after(0) {}
20+
timer = timers.after(0){}
2121
timer.cancel
2222
count -= 1
2323
end
@@ -29,7 +29,7 @@
2929
timers = IO::Event::Timers.new
3030

3131
while count > 0
32-
timer = timers.after(0) {}
32+
timer = timers.after(0){}
3333
timer.cancel!
3434
count -= 1
3535
end

benchmark/timers/after_n.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# frozen_string_literal: true
33

44
# Released under the MIT License.
5-
# Copyright, 2024, by Samuel Williams.
5+
# Copyright, 2024-2025, by Samuel Williams.
66

77
require "benchmark/ips"
88

@@ -17,7 +17,7 @@
1717
timers = Timers::Group.new
1818

1919
while count > 0
20-
timers.after(0) {}
20+
timers.after(0){}
2121
count -= 1
2222
end
2323

@@ -28,7 +28,7 @@
2828
timers = IO::Event::Timers.new
2929

3030
while count > 0
31-
timers.after(0) {}
31+
timers.after(0){}
3232
count -= 1
3333
end
3434

0 commit comments

Comments
 (0)