Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kernel#Sync: pass annotation: keyword to newly created Reactor #348

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
end

group :test do
gem "sus", "~> 0.29", ">= 0.29.1"
gem "sus", "~> 0.31"
gem "covered"
gem "decode"
gem "rubocop"
Expand Down
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
4 changes: 4 additions & 0 deletions test/kernel/async.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
Async(transient: true) do |task|
expect(task).to be(:transient?)
end

Async(annotation: 'foobar') do |task|
expect(task.annotation).to be == 'foobar'
end
end
end
end
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
Loading