Skip to content

Example of using switchback with futures? ..Or propose alternate way to accomplish? #22

@brizzbane

Description

@brizzbane

Love what you made. I've been wanting to figure this out for a while, but have been hesitant to ask.

Can you help me with this.., not sure if I'm understanding how to use get_hub().switch() correctly.

Here is an example of what I'm trying to accomplish..

def prepare_handle(self, ph):
    print('prepare handle self.users %s' % self.users)

    def handle_response(future, user):
        print('future %s' % future)


    request = cURLHTTPRequest('http://google.com')
    future = self.client.req(request)

         #   gruvi.get_hub().switch()
    with gruvi.switch_back(timeout=10) as switcher:
        print('here!!!')
        sigh = pyuv.Signal(gruvi.get_hub().loop)
        sigh.start(switcher, pyuv.Signal().SIGHUP)
        future.add_done_callback(functools.partial(switcher, future, 'asdf'))
        switcher.add_cleanup(sigh.close)
        gruvi.get_hub().switch()

So combining Fibers & (ultimately) results of the values of Futures. Didn't see any examples using gruvi.get_hub().switch() AND switchback.

MUCH appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions