PiPHP\GPIO\Interrupt\InterruptWatcher::watch PHP Method

watch() public method

public watch ( $timeout )
    public function watch($timeout)
    {
        $seconds = floor($timeout / 1000);
        $carry = $timeout - $seconds * 1000;
        $micro = $carry * 1000;
        $read = $write = [];
        $except = $this->streams;
        $streamSelect = $this->streamSelect;
        $result = @$streamSelect($read, $write, $except, $seconds, $micro);
        if (false === $result) {
            return false;
        }
        $triggers = [];
        foreach ($except as $pinNumber => $stream) {
            $value = fread($stream, 1);
            @rewind($stream);
            if ($value !== false) {
                $triggers[$pinNumber] = (int) $value;
            }
        }
        foreach ($triggers as $pinNumber => $value) {
            if (false === call_user_func($this->callbacks[$pinNumber], $this->pins[$pinNumber], $value)) {
                return false;
            }
        }
        return true;
    }