NAME
IPC::Manager::Role::Service::Requests - Role for handling request/response patterns in IPC services.
DESCRIPTION
This role provides functionality for sending requests and handling responses in a request/response pattern over IPC connections. It tracks pending responses and supports both callback-based and blocking response retrieval.
SYNOPSIS
package MyService;
use Role::Tiny;
with 'IPC::Manager::Role::Service::Requests';
sub client { ... } # Returns a client object
# Send a request with a callback
my $id = $service->send_request($peer => $request => sub {
my ($resp, $msg) = @_;
# Handle response
});
# Send a request and get response later
$id = $service->send_request($peer => $request);
# Get the response (blocks until available)
my $response = $service->get_response($id);
# Check if there are pending responses
if ($service->have_pending_responses) {
# ...
}
METHODS
- $service->clear_servicerequests_fields()
-
Clears all internal response tracking fields. Call this when resetting or reinitializing the service.
- $bool = $service->have_pending_responses()
-
Returns true if there are pending responses either waiting in the response hash or with active callbacks.
- $service->handle_response($resp, $msg)
-
Handles an incoming response message. If the response has an associated callback, it will be executed. Otherwise, the response is stored for later retrieval with
get_response(). - $id = $service->send_request($peer, $request, $cb)
-
Sends a request to the specified peer. If a callback
$cbis provided, it will be called when the response arrives. If no callback is provided, the response can be retrieved later withget_response().Returns the unique request ID.
- $response = $service->get_response($resp_id)
-
Retrieves the response for the given response ID. If the response is not yet available, returns undef. Throws an exception if the ID has a callback assigned or if no response was ever requested with that ID.
SOURCE
The source code repository for IPC::Manager can be found at https://github.com/exodist/IPC-Manager.
MAINTAINERS
AUTHORS
COPYRIGHT
Copyright Chad Granum <exodist7@gmail.com>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.