NAME

Sys::Async::Virt::Callback - Client side proxy to remote LibVirt event source

VERSION

v0.0.13

SYNOPSIS

my $cb = await $client->domain_event_register_any(
   $client->DOMAIN_EVENT_ID_LIFECYCLE );

while (my $event = await $cb->next_event) {
   my $dom = $event->{dom};

   # process the event
   if ($event->{event} == $dom->EVENT_STOPPED) {
      # Act on stopped domain
   }
);

DESCRIPTION

This class provides access to events generated on the remote; its design allows linear handling of the generated events, by presenting the events as a stream of futures coming from the server.

Events are buffered until they're read off the callback object. No events will get lost. However, since the server continues its operations, a domain could disappear if an event's handling is delayed too long.

CONSTRUCTOR

new

Not to be called directly; used internally by methods returning instances of this class.

DESTRUCTOR

DESTROY

Unregisters the callback from the server if it hasn't already been cancelled; not to be called directly: Perl calls this method when the value goes out of scope.

METHODS

next_event

my $f = $cb->next_event;

Returns a future which will resolve once the next event is available or until the callback is terminated using the cancel method.

Returns undef when the event stream has been cancelled and all pending events have been handled.

cancel

my $f = $cb->cancel;

Returns a future which will resolve once the callback has been unregistered from the server and all pending events (on the client) have been cleared.

SEE ALSO

LibVirt, Sys::Virt

LICENSE AND COPYRIGHT

Copyright (C) 2024 Erik Huelsmann

All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.