Skip to content

Commit

Permalink
Eliminate the fossilish deferred execution thing
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Mar 1, 2010
1 parent b98e611 commit b761e63
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/Soric3/Kernel.pm
Expand Up @@ -7,7 +7,7 @@ use MooseX::Declare;
# the configuration logic should be hard-coded, kept in a separate module
# with delegation... XXX investigate possible Moose models, study Kioku/DBIC

class Soric3::Kernel with Soric3::Meta::Alertable {
class Soric3::Kernel {
has _modules => (
isa => 'HashRef[Soric3::Module]',
is => 'bare',
Expand Down
21 changes: 12 additions & 9 deletions lib/Soric3/Module/Irc.pm
Expand Up @@ -51,7 +51,7 @@ class Soric3::Module::Irc extends Soric3::Module
}

class Soric3::Module::Irc::Connection
with (Soric3::Role::Alertable, Soric3::Role::SendQueue) {
with (Soric3::Role::AlertAt, Soric3::Role::SendQueue) {
use List::Util 'max';

has connection => (
Expand Down Expand Up @@ -79,10 +79,6 @@ class Soric3::Module::Irc::Connection
is => 'rw',
);

method new_sends() {
$self->alert if $self->is_ready;
}

method BUILD() {
$self->reg_cb(
registered => sub { shift->alert },
Expand Down Expand Up @@ -112,6 +108,10 @@ class Soric3::Module::Irc::Connection
);
}

method new_sends() {
$self->_service;
}

method is_ready() {
return ($self->next_send_time <= AnyEvent->now
&& $self->registered);
Expand All @@ -122,7 +122,7 @@ class Soric3::Module::Irc::Connection
AnyEvent->now - 10));
}

method _service() {
method _service_once() {
my ($best_prio, $best_msg, $best_cb) = (0, undef, undef);

$self->broadcast('Send', 'get_queued_send', $self->tag,
Expand Down Expand Up @@ -150,12 +150,15 @@ class Soric3::Module::Irc::Connection
return 1;
}

method react() {
method alert() {
return if !defined($self->backref);
$self->cancel_alert;

$self->_service while $self->is_ready;
while ($self->is_ready) {
$self->_service_once || return;
}

if ($self->registered && !$self->is_ready) {
if ($self->registered) {
$self->alert_at($self->next_send_time);
}
}
Expand Down

0 comments on commit b761e63

Please sign in to comment.