Skip to content

Commit

Permalink
Merge pull request #804 from cavinkwon/add_respond_to_missing_to_async
Browse files Browse the repository at this point in the history
Add respond_to_missing? for async/await
  • Loading branch information
pitr-ch authored Mar 8, 2019
2 parents b4b0542 + c1f6a17 commit 2307958
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/concurrent/async.rb
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,13 @@ def method_missing(method, *args, &block)
ivar
end

# Check whether the method is responsive
#
# @param [Symbol] method the method being called
def respond_to_missing?(method, include_private = false)
@delegate.respond_to?(method) || super
end

# Perform all enqueued tasks.
#
# This method must be called from within the executor. It must not be
Expand Down Expand Up @@ -383,6 +390,13 @@ def method_missing(method, *args, &block)
ivar.wait
ivar
end

# Check whether the method is responsive
#
# @param [Symbol] method the method being called
def respond_to_missing?(method, include_private = false)
@delegate.respond_to?(method) || super
end
end
private_constant :AwaitDelegator

Expand Down
10 changes: 10 additions & 0 deletions spec/concurrent/async_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ def many(*args, &block) nil; end
}.to raise_error(StandardError)
end

it 'returns the existence of the method' do
expect(subject.async.respond_to?(:echo)).to be_truthy
expect(subject.async.respond_to?(:not_exist_method)).to be_falsy
end

it 'returns a :pending IVar' do
val = subject.async.wait(1)
expect(val).to be_a Concurrent::IVar
Expand Down Expand Up @@ -224,6 +229,11 @@ def many(*args, &block) nil; end
}.to raise_error(StandardError)
end

it 'returns the existence of the method' do
expect(subject.await.respond_to?(:echo)).to be_truthy
expect(subject.await.respond_to?(:not_exist_method)).to be_falsy
end

it 'returns a :fulfilled IVar' do
val = subject.await.echo(5)
expect(val).to be_a Concurrent::IVar
Expand Down

0 comments on commit 2307958

Please sign in to comment.