Skip to content

Commit

Permalink
improved documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 11, 2011
1 parent c3d472d commit 714de84
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 39 deletions.
6 changes: 3 additions & 3 deletions lib/Mojo/IOLoop.pm
Expand Up @@ -825,7 +825,8 @@ Callback to be invoked if new data arrives on the connection.
$loop->one_tick('0.25');
$loop->one_tick(0);
Run reactor for exactly one tick.
Run reactor for roughly one tick and try not to block longer than the given
amount of time in seconds.
=head2 C<recurring>
Expand Down Expand Up @@ -881,8 +882,7 @@ singleton.
Mojo::IOLoop->start;
$loop->start;
Start the loop, this will block until C<stop> is called or return immediately
if the loop is already running.
Start the loop, this will block until C<stop> is called.
=head2 C<start_tls>
Expand Down
72 changes: 36 additions & 36 deletions lib/Mojo/IOWatcher.pm
Expand Up @@ -60,41 +60,6 @@ sub not_writing {
}

# "This was such a pleasant St. Patrick's Day until Irish people showed up."
sub _one_tick {
my $self = shift;

# I/O
my $poll = $self->_poll;
$poll->poll('0.025');
my $handles = $self->{handles};
$self->_sandbox('Read', $handles->{fileno $_}->{on_readable}, $_)
for $poll->handles(POLLIN | POLLHUP | POLLERR);
$self->_sandbox('Write', $handles->{fileno $_}->{on_writable}, $_)
for $poll->handles(POLLOUT);

# Wait for timeout
usleep 1000000 * '0.025' unless keys %{$self->{handles}};

# Timers
my $timers = $self->{timers} || {};
for my $id (keys %$timers) {
my $t = $timers->{$id};
my $after = $t->{after} || 0;
if ($after <= time - ($t->{started} || $t->{recurring} || 0)) {
warn "TIMER $id\n" if DEBUG;

# Normal timer
if ($t->{started}) { $self->cancel($id) }

# Recurring timer
elsif ($after && $t->{recurring}) { $t->{recurring} += $after }

# Handle timer
if (my $cb = $t->{cb}) { $self->_sandbox("Timer $id", $cb, $id) }
}
}
}

sub recurring { shift->_timer(pop, after => pop, recurring => time) }

sub remove {
Expand All @@ -106,7 +71,7 @@ sub remove {

sub start {
my $self = shift;
$self->{running}++;
return if $self->{running}++;
$self->_one_tick while $self->{running};
}

Expand Down Expand Up @@ -134,6 +99,41 @@ sub _timer {
return $id;
}

sub _one_tick {
my $self = shift;

# I/O
my $poll = $self->_poll;
$poll->poll('0.025');
my $handles = $self->{handles};
$self->_sandbox('Read', $handles->{fileno $_}->{on_readable}, $_)
for $poll->handles(POLLIN | POLLHUP | POLLERR);
$self->_sandbox('Write', $handles->{fileno $_}->{on_writable}, $_)
for $poll->handles(POLLOUT);

# Wait for timeout
usleep 25000 unless keys %{$self->{handles}};

# Timers
my $timers = $self->{timers} || {};
for my $id (keys %$timers) {
my $t = $timers->{$id};
my $after = $t->{after} || 0;
if ($after <= time - ($t->{started} || $t->{recurring} || 0)) {
warn "TIMER $id\n" if DEBUG;

# Normal timer
if ($t->{started}) { $self->cancel($id) }

# Recurring timer
elsif ($after && $t->{recurring}) { $t->{recurring} += $after }

# Handle timer
if (my $cb = $t->{cb}) { $self->_sandbox("Timer $id", $cb, $id) }
}
}
}

sub _poll { shift->{poll} ||= IO::Poll->new }

sub _sandbox {
Expand Down

0 comments on commit 714de84

Please sign in to comment.