The Perl and Raku Conference 2025: Greenville, South Carolina - June 27-29 Learn more

NAME

Net::Async::Pusher - support for pusher.com streaming event API

SYNOPSIS

#!/usr/bin/env perl
use strict;
use feature qw(say);
# For more details, enable this
# use Log::Any::Adapter qw(Stdout);
my $loop = IO::Async::Loop->new;
$loop->add(
my $pusher = Net::Async::Pusher->new
);
say "Connecting to pusher.com via websocket...";
my $sub = $pusher->connect(
key => 'de504dc5763aeef9ff52'
)->then(sub {
my ($conn) = @_;
say "Connection established. Opening channel.";
$conn->open_channel('live_trades')
})->then(sub {
my ($ch) = @_;
say "Have channel, setting up event handler for 'trade' event.";
$ch->subscribe(trade => sub {
my ($ev, $data) = @_;
say "New trade - price " . $data->{price} . ", amount " . $data->{amount};
});
})->get;
say "Subscribed and waiting for events...";
$loop->run;
$sub->()->get;

DESCRIPTION

Provides basic integration with the https://pusher.com|Pusher API.

connect

Connects to a server using a key.

my $conn = $pusher->connect(
key => 'abc123'
)->get;

Resolves to a Net::Async::Pusher::Connection.

INHERITED METHODS

IO::Async::Notifier

add_child, adopt_future, adopted_futures, can_event, children, configure, configure_unknown, debug_printf, get_loop, invoke_error, invoke_event, loop, make_event_cb, maybe_invoke_event, maybe_make_event_cb, new, notifier_name, parent, remove_child, remove_from_parent

AUTHOR

Tom Molesworth <TEAM@cpan.org>

LICENSE

Copyright Tom Molesworth 2015-2021. Licensed under the same terms as Perl itself.