Created
November 22, 2016 14:33
-
-
Save jberger/9c9b7c2f3f99f2a20b534985362450f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package SomeObject; | |
sub open { | |
my $self = shift; | |
$self->on(connect => \&connect); | |
$self->trigger_open; # low-level start conneection | |
} | |
sub connect { | |
my $self = shift; | |
my $delay = Mojo::IOLoop->delay( | |
sub { | |
my $delay = shift; | |
$self->config_a($delay->begin); | |
$self->config_b($delay->begin); | |
}, | |
sub { | |
$self->attach_normal_listeners; | |
}, | |
); | |
} | |
# likewise for config_b | |
sub config_a { | |
my ($self, $cb) = @_; | |
my $delay = Mojo::IOLoop->delay( | |
sub { | |
my $delay = shift; | |
$self->ua->get($config_a1, $delay->begin) | |
}, | |
sub { | |
my $delay = shift; | |
$self->ua->get($config_a2, $delay->begin) | |
}, | |
sub { | |
$self->$cb(); | |
} | |
) | |
} | |
sub attach_normal_listeners { | |
my $self = shift; | |
$self->on(event1 => sub { ... }); | |
$self->on(event2 => sub { ... }); | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment