Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
class SocketStreamAdapter extends EventEmitter
{
const DELAY_TICK = 0.01;
const DURATION_TICK = 0;
protected $loop;
protected $socket;
protected $tid = null;
public function __construct(LoopInterface $loop, $socket)
{
$this->loop = $loop;
$this->socket = $socket;
$this->resume();
}
public function resume()
{
$this->tid = $this->loop->addPeriodicTimer(self::DELAY_TICK, array($this, 'tick'));
}
public function pause()
{
$this->loop->removeTimer($this->tid);
$this->tid = null;
}
// a polling tick function
public function tick()
{
$r = array($this->socket);
socket_select($r, $w=null, $e=null, 0, self::DURATION_TICK * 1000000);
if ($r) {
$that->emit('ready', array($this->socket, $this));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.