On Tue, Nov 6, 2018 at 6:42 AM Chris Withers <ch...@simplistix.co.uk> wrote:
> On 05/11/2018 18:32, meejah wrote: > > Chris Withers <ch...@simplistix.co.uk> writes: > > > >> So, separate question: I have a client that's making a connection to a > >> websocket from a server. The client needs to send an "auth" message > >> once the websocket is up, and the client code shouldn't progress until > >> it receives an affirmative response. How do I do this in a > >> non-blocking way when using twisted? (inside an inlineDeferred method > >> in this case!) > > > > There's nothing really special about an @inlineCallbacks method -- it > > just returns a Deferred so you can handle it like any other > > Deferred-returning method. > > Thanks, but the special bit I was asking about is having my > application's logical flow pause until the websocket is successfully up > and a successful response has been received, all without blocking the > reactor. > > How do I do that? > > Put the rest of your code in a callback on a Deferred that fires when the event you're interested in happens. When using inlineCallbacks, that's like: yield the_event_youre_interested_in # ... more code At least, this is the extremely-localized solution to the problem. There are many possible ways to structure such a thing. It's easy to describe this one because you said you're using inlineCallbacks and didn't say anything else about how your code is organized. Jean-Paul
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python