Skip to content

Commit

Permalink
Kernel#Sync: pass annotation: keyword to newly created Reactor
Browse files Browse the repository at this point in the history
  • Loading branch information
paddor committed Oct 1, 2024
1 parent 5ab35c5 commit 665534d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/kernel/sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module Kernel
#
# @public Since `stable-v1`.
# @asynchronous Will block until given block completes executing.
def Sync(&block)
def Sync(*arguments, **options, &block)
if task = ::Async::Task.current?
yield task
elsif scheduler = Fiber.scheduler
Expand All @@ -25,7 +25,7 @@ def Sync(&block)
reactor = Async::Reactor.new

begin
return reactor.run(finished: ::Async::Condition.new, &block).wait
return reactor.run(*arguments, **options, finished: ::Async::Condition.new, &block).wait
ensure
Fiber.set_scheduler(nil)
end
Expand Down
6 changes: 6 additions & 0 deletions test/kernel/sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@

expect(result).to be == value
end

it "passes options through to initial task" do
Sync(annotation: 'foobar') do |task|
expect(task.annotation).to be == 'foobar'
end
end

it "can run inside reactor" do
Async do |task|
Expand Down

0 comments on commit 665534d

Please sign in to comment.