I think this is what you want:
async sub fetch { my ( $self, $params ) = @_; my $loop = IO::Async::Loop->new; my $received = Future->new(); my @received; my $client = Net::Async::WebSocket::Client->new( on_text_frame => sub { my ( $clientself, $frame ) = @_; push @data_received, $frame; if ( $num_items_received >= $MAX_HELLOS ) { $received->done(); } } ); $loop->add( $client ); defer { $client->closenow; } ...; # $client->connect. ...; # $client->send_text_frame loop. $loop->await( $received ); return \@data_received; }
Equivalent:
async sub fetch { my ( $self, $params ) = @_; my $loop = IO::Async::Loop->new; my $received = $loop->new_future(); # <--- my @received; my $client = Net::Async::WebSocket::Client->new( on_text_frame => sub { my ( $clientself, $frame ) = @_; push @data_received, $frame; if ( $num_items_received >= $MAX_HELLOS ) { $received->done(); } } ); $loop->add( $client ); defer { $client->closenow; } ...; # $client->connect. ...; # $client->send_text_frame loop. await $received; # <--- return \@data_received; }
Completely untested.
In reply to Re: IO::Async::Loop in multiple modules all loaded
by ikegami
in thread IO::Async::Loop in multiple modules all loaded
by bliako
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |