sub wait { my $self = shift; my(@args, $error) $self->once(finish => sub { shift->ioloop->stop; @args = @_ }); $self->once(error => sub { shift->ioloop->stop; $error = $_[0] || '' }); $self->ioloop->start; die $error if defined $error; return wantarray ? @args : $args[0]; }