diff --git a/lib/async/reactor.rb b/lib/async/reactor.rb index 947775bb..33095227 100644 --- a/lib/async/reactor.rb +++ b/lib/async/reactor.rb @@ -47,9 +47,7 @@ class Reactor < Node # running. def self.run(*arguments, **options, &block) if current = Task.current? - reactor = current.reactor - - return reactor.async(*arguments, **options, &block) + return current.async(*arguments, **options, &block) else reactor = self.new diff --git a/lib/async/task.rb b/lib/async/task.rb index 5d8d1324..765ebccc 100644 --- a/lib/async/task.rb +++ b/lib/async/task.rb @@ -81,7 +81,7 @@ def initialize(reactor, parent = Task.current?, logger: nil, finished: nil, **op @result = nil @finished = finished - @logger = logger + @logger = logger || parent&.instance_variable_get(:@logger) @fiber = make_fiber(&block) end diff --git a/spec/async/logger_spec.rb b/spec/async/logger_spec.rb index 0f44bd0e..7d3d8498 100644 --- a/spec/async/logger_spec.rb +++ b/spec/async/logger_spec.rb @@ -56,6 +56,7 @@ it "can use parent logger" do current_logger = Console.logger + child = nil Async(logger: logger) do |parent| child = parent.async{|task| task.yield} @@ -66,6 +67,8 @@ expect(Console.logger).to be == logger end.wait + expect(child.logger).to be == logger + expect(Console.logger).to be == current_logger end end