Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subscribeAndWaitForMessage timeout - enhancement #119

Open
lipflip opened this issue Apr 7, 2021 · 1 comment
Open

subscribeAndWaitForMessage timeout - enhancement #119

lipflip opened this issue Apr 7, 2021 · 1 comment

Comments

@lipflip
Copy link

lipflip commented Apr 7, 2021

It would be great to have some timeout option, otherwise you have an endless loop,

this is not ok in some situations.

@danieleliberti
Copy link

public function subscribeAndWaitForMessage($topic, $qos): string
    {
        $this->subscribe(
            [
                $topic => [
                    'qos' => $qos,
                    'function' => '__direct_return_message__'
                ]
            ]
        );

        
        $microtimeStart = microtime(true);
        do {
            $return = $this->proc();
            $microtime = microtime(true);
            
            if (($microtime - $microtimeStart) > 30  ){
                $return = '{"rtErr":"Time exceeded !"}';
            }
        } while ($return === true);
        return $return;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants