Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Are views a coroutines? #15

Closed
JerzySpendel opened this issue Nov 20, 2016 · 2 comments
Closed

Are views a coroutines? #15

JerzySpendel opened this issue Nov 20, 2016 · 2 comments

Comments

@JerzySpendel
Copy link

Let's take a look at the documentation example:


from growler import App

app = App()

@app.use
def log_file(req, res):
    print("<{ip}> {req_path}".format(ip=req.ip, req_path=req.path))

@app.get("/")
def index_file(req, res):
    res.send_text("index.")

app.create_server_and_run_forever(host='0.0.0.0', port='8080')

Is index_file a coroutine from which I could do a yield from?

@akubera
Copy link
Member

akubera commented Nov 20, 2016

Growler accepts both normal functions and coroutine functions as middleware, and will handle each appropriately.

Just adorn the function with @asyncio.coroutine and you can yield from all you like.

Example 2 demonstrates this.

Note, I'm going to drop py3.4 support with my next version (v0.9.x), and I recommend using async & await notation instead of asyncio.coroutine

@JerzySpendel
Copy link
Author

Ok, super! :) I didn't find this example in documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants