Skip to content

Commit

Permalink
Fix child task inheriting parent logger.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Apr 10, 2021
1 parent 61a1650 commit 5d5f587
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
4 changes: 1 addition & 3 deletions lib/async/reactor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/async/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions spec/async/logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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

0 comments on commit 5d5f587

Please sign in to comment.