class Call
Represents context for a single RPC call.
Definitions
def initialize(request, response = nil, deadline: nil)
Initialize a new RPC call context.
Signature
-
parameter
requestProtocol::HTTP::Request The HTTP request
-
parameter
responseProtocol::HTTP::Response | Nil The HTTP response (for setting metadata and trailers)
-
parameter
deadlineAsync::Deadline | Nil Deadline for the call
Implementation
def initialize(request, response = nil, deadline: nil)
@request = request
@response = response
@deadline = deadline
@cancelled = false
end
attr_reader :request
Signature
-
attribute
Protocol::HTTP::Request The underlying HTTP request.
attr_reader :response
Signature
-
attribute
Protocol::HTTP::Response | Nil The HTTP response.
attr_reader :deadline
Signature
-
attribute
Async::Deadline | Nil The deadline for this call.
def metadata
Extract metadata from request headers.
Signature
-
returns
Hash Custom metadata key-value pairs
Implementation
def metadata
@metadata ||= Methods.extract_metadata(@request.headers)
end
def deadline_exceeded?
Check if the deadline has expired.
Signature
-
returns
Boolean trueif the deadline has expired,falseotherwise
Implementation
def deadline_exceeded?
@deadline&.expired? || false
end
def time_remaining
Get the time remaining until the deadline.
Signature
-
returns
Numeric | Nil Seconds remaining, or
Nilif no deadline is set
Implementation
def time_remaining
@deadline&.remaining
end
def cancel!
Mark this call as cancelled.
Implementation
def cancel!
@cancelled = true
end
def cancelled?
Check if the call was cancelled.
Signature
-
returns
Boolean trueif the call was cancelled,falseotherwise
Implementation
def cancelled?
@cancelled
end
def peer
Get peer information (client address).
Signature
-
returns
String | Nil The peer address as a string, or
Nilif not available
Implementation
def peer
@request.peer&.to_s
end