friends-of-reactphp / stomp

STOMP bindings for ReactPHP.
MIT License
115 stars 42 forks source link

Connect asynchronously #19

Open igorw opened 11 years ago

igorw commented 11 years ago

Currently the connect call itself is blocking.

We should call stream_socket_client with the STREAM_CLIENT_ASYNC_CONNECT flag. But that means we cannot tell connection failure at connect time.

We can only detect connection failure if we have reactphp/react#113. So that needs to be fixed first.

nrk commented 11 years ago

There's a workaround even without the need for reactphp/react#113: you set the STREAM_CLIENT_ASYNC_CONNECT flag and subscribe for a write event on the connecting stream, if stream_socket_get_name($socket, true) === false when the write event kicks then it means that the connection has been refused.

I do that in Predis\Async and it seems to work quite well, see here and here for the related code.

igorw commented 11 years ago

That's quite nice, ideally we would have something for that in react core.