Skip to content

Commit 2307958

Browse files
authored
Merge pull request #804 from cavinkwon/add_respond_to_missing_to_async
Add respond_to_missing? for async/await
2 parents b4b0542 + c1f6a17 commit 2307958

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

lib/concurrent/async.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,13 @@ def method_missing(method, *args, &block)
333333
ivar
334334
end
335335

336+
# Check whether the method is responsive
337+
#
338+
# @param [Symbol] method the method being called
339+
def respond_to_missing?(method, include_private = false)
340+
@delegate.respond_to?(method) || super
341+
end
342+
336343
# Perform all enqueued tasks.
337344
#
338345
# This method must be called from within the executor. It must not be
@@ -383,6 +390,13 @@ def method_missing(method, *args, &block)
383390
ivar.wait
384391
ivar
385392
end
393+
394+
# Check whether the method is responsive
395+
#
396+
# @param [Symbol] method the method being called
397+
def respond_to_missing?(method, include_private = false)
398+
@delegate.respond_to?(method) || super
399+
end
386400
end
387401
private_constant :AwaitDelegator
388402

spec/concurrent/async_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ def many(*args, &block) nil; end
158158
}.to raise_error(StandardError)
159159
end
160160

161+
it 'returns the existence of the method' do
162+
expect(subject.async.respond_to?(:echo)).to be_truthy
163+
expect(subject.async.respond_to?(:not_exist_method)).to be_falsy
164+
end
165+
161166
it 'returns a :pending IVar' do
162167
val = subject.async.wait(1)
163168
expect(val).to be_a Concurrent::IVar
@@ -224,6 +229,11 @@ def many(*args, &block) nil; end
224229
}.to raise_error(StandardError)
225230
end
226231

232+
it 'returns the existence of the method' do
233+
expect(subject.await.respond_to?(:echo)).to be_truthy
234+
expect(subject.await.respond_to?(:not_exist_method)).to be_falsy
235+
end
236+
227237
it 'returns a :fulfilled IVar' do
228238
val = subject.await.echo(5)
229239
expect(val).to be_a Concurrent::IVar

0 commit comments

Comments
 (0)