Re: "blocking" on a response to a client

Jean-Paul Calderone <[email protected]>
Newsgroups gmane.comp.python.twisted
Message-ID <CAEeXt4OJmF04sNKZA9JXWaKyX1=h9ixsLbLzk4YOPaJ-C99cyA@mail.gmail.com>
On Tue, Nov 6, 2018 at 6:42 AM Chris Withers <[email protected]> wrote:

> On 05/11/2018 18:32, meejah wrote:
> > Chris Withers <[email protected]> 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
[email protected]
https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.