[prev in list] [next in list] [prev in thread] [next in thread] 

List:       uwsgi
Subject:    [uWSGI] uWSGI async mode
From:       roberto () unbit ! it (Roberto De Ioris)
Date:       2011-09-22 17:50:57
Message-ID: effca3f46833afbabd6069fb77ecfc52.squirrel () manage ! unbit ! it
[Download RAW message or body]


> Hi Roberto,what do you think about this:
>
> in main loop:
>    cl = my_http_client()
>    # send returns without blocking
>    uwsgi.send( cl.client, data, read_callback )
>    uwsgi.wait_fd_read( cl.client, timeout, write_callback )
>    # yield returns core and callback
>    (uwsgi_core, callback) =  yield ''
>    callback()
>
> my_http_client:
>   def __init__(self):
>       self.client = uwsgi.async_connect('74.125.232.115:80')
>   def read_callback(self)
>         buf = uwsgi.recv(client, 1024)
>
>   def write_callback(self)
>         ...
>
> ####################
> with this kind of api it is also possible to write code like this:
>
> in main loop:
>    client = uwsgi.async_connect('74.125.232.115:80')
>    uwsgi.send( cl.client, data, partial(http_proto.write_callback, client)
> )
>    uwsgi.wait_fd_read( cl.client, timeout,
> partial(http_proto.read_callback, client) )
>    (uwsgi_core, callback) =  yield ''
>    # callback already curried and will be called with fd argument
>    callback()
>
> http_proto:
>   def read_callback(self, fd)
>         buf = uwsgi.recv(fd, 1024)
>
>   def write_callback(self, fd)
>         ...
>
>
> by partial call i mean here curry pattern from functools
>


I like the callback approach, i will probably need to tweak some api
function but it should be easy.

Probably i should even add a way to avoid re-registering descriptor after
each event.



-- 
Roberto De Ioris
http://unbit.it

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic