Skip to content

Instantly share code, notes, and snippets.

@acrylic-origami
Created January 5, 2017 16:54
Show Gist options
  • Save acrylic-origami/ccb1c0c4220a9e789f788c9f0521fd45 to your computer and use it in GitHub Desktop.
Save acrylic-origami/ccb1c0c4220a9e789f788c9f0521fd45 to your computer and use it in GitHub Desktop.
Called using HH\Asio\join(new Forever()->loop()); in the top level
<?hh // strict
class Forever {
private ?Awaitable<?(mixed, int)> $hook = null;
public function __construct() {
}
public async function loop(): Awaitable<void> {
$generator = $this->sub();
await ($this->hook = $generator->next());
}
private async function sub(): \AsyncIterator<int> {
await \HH\Asio\usleep(1);
invariant(!is_null($this->hook), '');
await $this->hook;
yield 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment