Skip to content
Merged
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 async-grpc.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ Gem::Specification.new do |spec|

spec.add_dependency "async", ">= 2.38.0"
spec.add_dependency "async-http"
spec.add_dependency "protocol-grpc", "~> 0.11.0"
spec.add_dependency "protocol-grpc", "~> 0.12.0"
spec.add_dependency "protocol-http", "~> 0.60"
end
19 changes: 6 additions & 13 deletions lib/async/grpc/dispatcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# Copyright, 2025-2026, by Samuel Williams.

require "async"
require "async/deadline"

require_relative "error"

Expand Down Expand Up @@ -71,8 +70,8 @@ def invoke_service(service, handler_method, input, output, call)
end
end

def dispatch_to_service(service, handler_method, input, output, call, deadline, parent: Async::Task.current)
if deadline
def dispatch_to_service(service, handler_method, input, output, call, parent: Async::Task.current)
if deadline = call.deadline
parent.with_timeout(deadline.remaining, DeadlineExceededError) do
invoke_service(service, handler_method, input, output, call)
end
Expand Down Expand Up @@ -137,22 +136,16 @@ def dispatch(request)
# Create response object:
response = Protocol::HTTP::Response[200, response_headers, output]

# Parse deadline from timeout header:
timeout = Protocol::GRPC::Methods.parse_timeout(request.headers["grpc-timeout"])
deadline = if timeout
Async::Deadline.start(timeout)
end

# Create call context with request and response:
call = Protocol::GRPC::Call.new(request, response, deadline: deadline)
# Create call context with request, response and deadline:
call = Protocol::GRPC::Call.for(request, response)

if rpc_descriptor.streaming?
Async do |task|
dispatch_to_service(service, handler_method, input, output, call, deadline, parent: task)
dispatch_to_service(service, handler_method, input, output, call, parent: task)
end
else
# Unary call:
dispatch_to_service(service, handler_method, input, output, call, deadline)
dispatch_to_service(service, handler_method, input, output, call)
end

return response
Expand Down
Loading