8000 Use simpler interface for emitting warnings, and add shim for Console… · socketry/async@4a7549e · GitHub
[go: up one dir, main page]

Skip to content

Commit 4a7549e

Browse files
committed
Use simpler interface for emitting warnings, and add shim for Console gem.
1 parent 1c70c17 commit 4a7549e

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
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"
2727

28-
spec.add_dependency "console", "~> 1.26"
28+
spec.add_dependency "console", "~> 1.29"
2929
spec.add_dependency "fiber-annotation"
3030
spec.add_dependency "io-event", ["~> 1.6", ">= 1.6.5"]
3131
end

lib/async/console.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# frozen_string_literal: true
2+
3+
# Released under the MIT License.
4+
# Copyright, 2024, by Samuel Williams.
5+
6+
module Async
7+
# Shims for the console gem, redirecting warnings and above to `Kernel#warn`.
8+
#
9+
# If you require this file, the `async` library will not depend on the `console` gem.
10+
#
11+
# That includes any gems that sit within the `Async` namespace.
12+
#
13+
# This is an experimental feature.
14+
module Console
15+
def self.debug(...)
16+
end
17+
18+
def self.info(...)
19+
end
20+
21+
def self.warn(*arguments, exception: nil, **options)
22+
if exception
23+
super(*arguments, exception.full_message, **options)
24+
else
25+
super(*arguments, **options)
26+
end
27+
end
28+
29+
def self.error(...)
30+
self.warn(...)
31+
end
32+
33+
def self.fatal(...)
34+
self.warn(...)
35+
end
36+
end
37+
end

lib/async/task.rb

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

1010
require "fiber"
11-
require "console/event/failure"
11+
require "console"
1212

1313
require_relative "node"
1414
require_relative "condition"
@@ -198,9 +198,7 @@ def run(*arguments)
198198
rescue => error
199199
# I'm not completely happy with this overhead, but the alternative is to not log anything which makes debugging extremely difficult. Maybe we can introduce a debug wrapper which adds extra logging.
200200
if @finished.nil?
201-
Console::Event::Failure.for(error).emit(self, "Task may have ended with unhandled exception.", severity: :warn)
202-
else
203-
# Console::Event::Failure.for(error).emit(self, severity: :debug)
201+
Console.warn(self, "Task may have ended with unhandled exception.", exception: error)
204202
end
205203

206204
raise

0 commit comments

Comments
 (0)
0