Skip to content

Commit

Permalink
Use correct uv flags to prevent UvReactor::tick() from hanging in edg…
Browse files Browse the repository at this point in the history
…e-case scenarios
  • Loading branch information
rdlowrey committed Aug 12, 2015
1 parent 7df9b17 commit 3d1fde0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG
@@ -0,0 +1,13 @@
# dev

- n/a

### 1.0.1

- Fix bug preventing UvReactor::tick() from returning when no
events are ready for a single active IO watcher.

1.0.0
-----

- Initial stable API release
7 changes: 4 additions & 3 deletions lib/UvReactor.php
Expand Up @@ -90,7 +90,8 @@ public function run(callable $onStart = null) {
if (empty($this->keepAliveCount) || $this->state <= self::STOPPED) {
break;
}
\uv_run($this->loop, \UV::RUN_DEFAULT | (empty($this->immediates) ? \UV::RUN_ONCE : \UV::RUN_NOWAIT));
$flags = \UV::RUN_ONCE | ($this->immediates ? \UV::RUN_NOWAIT : 0);
\uv_run($this->loop, $flags);
}

\gc_collect_cycles();
Expand Down Expand Up @@ -148,8 +149,8 @@ public function tick($noWait = false) {
}

// Check the conditional again because a manual stop() could've changed the state
if ($this->state) {
$flags = $noWait || !empty($this->immediates) ? (\UV::RUN_NOWAIT | \UV::RUN_ONCE) : \UV::RUN_ONCE;
if ($this->state > 0) {
$flags = ($noWait || $this->immediates) ? (\UV::RUN_DEFAULT | \UV::RUN_NOWAIT) : \UV::RUN_ONCE;
\uv_run($this->loop, $flags);
}

Expand Down

0 comments on commit 3d1fde0

Please sign in to comment.