Skip to content

Commit

Permalink
Use simpler interface for emitting warnings, and add shim for Console…
Browse files Browse the repository at this point in the history
… gem.
  • Loading branch information
ioquatix committed Nov 6, 2024
1 parent 1c70c17 commit 4a7549e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
2 changes: 1 addition & 1 deletion async.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Gem::Specification.new do |spec|

spec.required_ruby_version = ">= 3.1"

spec.add_dependency "console", "~> 1.26"
spec.add_dependency "console", "~> 1.29"
spec.add_dependency "fiber-annotation"
spec.add_dependency "io-event", ["~> 1.6", ">= 1.6.5"]
end
37 changes: 37 additions & 0 deletions lib/async/console.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2024, by Samuel Williams.

module Async
# Shims for the console gem, redirecting warnings and above to `Kernel#warn`.
#
# If you require this file, the `async` library will not depend on the `console` gem.
#
# That includes any gems that sit within the `Async` namespace.
#
# This is an experimental feature.
module Console
def self.debug(...)
end

def self.info(...)
end

def self.warn(*arguments, exception: nil, **options)
if exception
super(*arguments, exception.full_message, **options)
else
super(*arguments, **options)
end
end

def self.error(...)
self.warn(...)
end

def self.fatal(...)
self.warn(...)
end
end
end
6 changes: 2 additions & 4 deletions lib/async/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Copyright, 2023, by Math Ieu.

require "fiber"
require "console/event/failure"
require "console"

require_relative "node"
require_relative "condition"
Expand Down Expand Up @@ -198,9 +198,7 @@ def run(*arguments)
rescue => error
# 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.
if @finished.nil?
Console::Event::Failure.for(error).emit(self, "Task may have ended with unhandled exception.", severity: :warn)
else
# Console::Event::Failure.for(error).emit(self, severity: :debug)
Console.warn(self, "Task may have ended with unhandled exception.", exception: error)
end

raise
Expand Down

0 comments on commit 4a7549e

Please sign in to comment.