I personally recommend against using generators in any form in a
sans-io protocol implementation. Are you absolutely sure that you
need them? Do you understand what the responsibilities of a
sans-io protocol are?
Hi.I'm trying to make sans-io library.
- Protocol works over http, so I've just passing Request object with method, url, data, etc. fields to user and receive Response object (json in this case).
- I'm using generators for simplification of holding state of multirequest actions. Something like this:
def login():
response = yield Request(...) # check server state
# update state with response
response = yield Request(...) # actually login
yield None
def act(generator):
response = None
while True:
request = generator.send(response)
if request is None:
return response
response = # do io
act(login())
This solve problem multistep actions. The downside is that all your protocol functions, event if they have only one request and don't need response at all, must be generators.
Is it ok to send just abstract Request and receive abstract Response (not just bytes)?
Is there a better solution for multirequest actions?
_______________________________________________ Async-sig mailing list Async-sig@python.org https://mail.python.org/mailman/listinfo/async-sig Code of Conduct: https://www.python.org/psf/codeofconduct/