Skip to content

Commit 38cb5ea

Browse files
committed
Update dependency on console gem and modernize usage.
1 parent 44272b4 commit 38cb5ea

File tree

12 files changed

+29
-28
lines changed

12 files changed

+29
-28
lines changed

async.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
2525

2626
spec.required_ruby_version = ">= 3.1.1"
2727

28-
spec.add_dependency "console", "~> 1.10"
28+
spec.add_dependency "console", ["~> 1.25", ">= 1.25.2"]
2929
spec.add_dependency "fiber-annotation"
3030
spec.add_dependency "io-event", ["~> 1.5", ">= 1.5.1"]
3131
spec.add_dependency "timers", "~> 4.1"

examples/capture/capture.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def strace(pid, duration = 60)
8383

8484
_, status = Process.waitpid2(pid)
8585

86-
Console.logger.error(status) do |buffer|
86+
Console.error(status) do |buffer|
8787
buffer.puts first_line
8888
end unless status.success?
8989

@@ -92,28 +92,28 @@ def strace(pid, duration = 60)
9292

9393
pids.each do |pid|
9494
start_times = getrusage(pid)
95-
Console.logger.info("Process #{pid} start times:", start_times)
95+
Console.info("Process #{pid} start times:", start_times)
9696

9797
# sleep 60
9898
summary = strace(pid)
9999

100-
Console.logger.info("strace -p #{pid}") do |buffer|
100+
Console.info("strace -p #{pid}") do |buffer|
101101
summary.each do |fields|
102102
buffer.puts fields.inspect
103103
end
104104
end
105105

106106
end_times = getrusage(pid)
107-
Console.logger.info("Process #{pid} end times:", end_times)
107+
Console.info("Process #{pid} end times:", end_times)
108108

109109
if total = summary[:total]
110110
process_duration = end_times.utime - start_times.utime
111111
wait_duration = summary[:total][:seconds]
112112

113-
Console.logger.info("Process Waiting: #{wait_duration.round(4)}s out of #{process_duration.round(4)}s") do |buffer|
113+
Console.info("Process Waiting: #{wait_duration.round(4)}s out of #{process_duration.round(4)}s") do |buffer|
114114
buffer.puts "Wait percentage: #{(wait_duration / process_duration * 100.0).round(2)}%"
115115
end
116116
else
117-
Console.logger.warn("No system calls detected.")
117+
Console.warn("No system calls detected.")
118118
end
119119
end

examples/hup-test/child.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
Async do |task|
1111
while true
1212
task.async do
13-
Console.logger.info("Child running.")
13+
Console.info("Child running.")
1414
sleep 0.1
1515
end.wait
1616
end

examples/hup-test/main.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
while true
1010
pid = Process.spawn("./child.rb")
11-
Console.logger.info("Spawned child.", pid: pid)
11+
Console.info("Spawned child.", pid: pid)
1212
sleep 2
13-
Console.logger.info("Sending HUP to child.", pid: pid)
13+
Console.info("Sending HUP to child.", pid: pid)
1414
Process.kill(:HUP, pid)
1515
status = Process.waitpid(pid)
16-
Console.logger.info("Child exited.", pid: pid, status: status)
16+
Console.info("Child exited.", pid: pid, status: status)
1717
end

lib/async/barrier.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require 'async/barrier'
99

1010
barrier = Async::Barrier.new
1111
Sync do
12-
Console.logger.info("Barrier Example: sleep sort.")
12+
Console.info("Barrier Example: sleep sort.")
1313

1414
# Generate an array of 10 numbers:
1515
numbers = 10.times.map{rand(10)}
@@ -26,7 +26,7 @@ Sync do
2626
# Wait for all the numbers to be sorted:
2727
barrier.wait
2828

29-
Console.logger.info("Sorted", sorted)
29+
Console.info("Sorted", sorted)
3030
ensure
3131
# Ensure all the tasks are stopped when we exit:
3232
barrier.stop

lib/async/condition.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ Sync do
99
condition = Async::Condition.new
1010

1111
Async do
12-
Console.logger.info "Waiting for condition..."
12+
Console.info "Waiting for condition..."
1313
value = condition.wait
14-
Console.logger.info "Condition was signalled: #{value}"
14+
Console.info "Condition was signalled: #{value}"
1515
end
1616

1717
Async do |task|
1818
task.sleep(1)
19-
Console.logger.info "Signalling condition..."
19+
Console.info "Signalling condition..."
2020
condition.signal("Hello World")
2121
end
2222
end

lib/async/scheduler.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ def run(...)
369369

370370
return initial_task
371371
ensure
372-
Console.logger.debug(self) {"Exiting run-loop because #{$! ? $! : 'finished'}."}
372+
Console.debug(self) {"Exiting run-loop because #{$! ? $! : 'finished'}."}
373373
end
374374

375375
# Start an asynchronous task within the specified reactor. The task will be
@@ -395,7 +395,7 @@ def async(*arguments, **options, &block)
395395
# - Avoid scheduler overhead if no blocking operation is performed.
396396
task.run(*arguments)
397397

398-
# Console.logger.debug "Initial execution of task #{fiber} complete (#{result} -> #{fiber.alive?})..."
398+
# Console.debug "Initial execution of task #{fiber} complete (#{result} -> #{fiber.alive?})..."
399399
return task
400400
end
401401

lib/async/semaphore.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ Sync do
1717
# Search for the terms:
1818
terms.each do |term|
1919
semaphore.async do |task|
20-
Console.logger.info("Searching for #{term}...")
20+
Console.info("Searching for #{term}...")
2121
response = Net::HTTP.get(URI "https://www.google.com/search?q=#{term}")
22-
Console.logger.info("Got response #{response.size} bytes.")
22+
Console.info("Got response #{response.size} bytes.")
2323
end
2424
end
2525
end

lib/async/task.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# Copyright, 2023, by Math Ieu.
99

1010
require 'fiber'
11+
require 'console/event/failure'
1112

1213
require_relative 'node'
1314
require_relative 'condition'
@@ -335,15 +336,15 @@ def failed!(exception = false, propagate = true)
335336
raise exception
336337
elsif @finished.nil?
337338
# If no one has called wait, we log this as a warning:
338-
Console.logger.warn(self, "Task may have ended with unhandled exception.", exception)
339+
Console::Event::Failure.for(exception).emit(self, "Task may have ended with unhandled exception.", severity: :warn)
339340
else
340-
Console.logger.debug(self, exception)
341+
Console::Event::Failure.for(exception).emit(self, severity: :debug)
341342
end
342343
end
343344
end
344345

345346
def stopped!
346-
# Console.logger.info(self, status:) {"Task #{self} was stopped with #{@children&.size.inspect} children!"}
347+
# Console.info(self, status:) {"Task #{self} was stopped with #{@children&.size.inspect} children!"}
347348
@status = :stopped
348349

349350
stopped = false
@@ -374,15 +375,15 @@ def schedule(&block)
374375

375376
begin
376377
completed!(yield)
377-
# Console.logger.debug(self) {"Task was completed with #{@children.size} children!"}
378+
# Console.debug(self) {"Task was completed with #{@children.size} children!"}
378379
rescue Stop
379380
stopped!
380381
rescue StandardError => error
381382
failed!(error, false)
382383
rescue Exception => exception
383384
failed!(exception, true)
384385
ensure
385-
# Console.logger.info(self) {"Task ensure $! = #{$!} with #{@children&.size.inspect} children!"}
386+
# Console.info(self) {"Task ensure $! = #{$!} with #{@children&.size.inspect} children!"}
386387
finish!
387388
end
388389
end

lib/async/waiter.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Sync do
3838
# Stop all tasks which we don't care about:
3939
barrier.stop
4040

41-
Console.logger.info("Smallest", numbers)
41+
Console.info("Smallest", numbers)
4242
end
4343
~~~
4444

test/async/task.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ def sleep_forever
761761

762762
expect(task.result).to be_nil
763763

764-
Console.logger.debug(self) {"Stopping task..."}
764+
Console.debug(self) {"Stopping task..."}
765765
task.stop
766766

767767
expect(task.result).to be_nil

test/kernel/sync.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
end
3737

3838
it "can propagate error without logging them" do
39-
expect(Console.logger).not.to receive(:error)
39+
expect(Console).not.to receive(:error)
4040

4141
expect do
4242
Sync do

0 commit comments

Comments
 (0)