| a | b | |
|---|
| 0 | 0 | | def my_awesome_application(environ): |
|---|
| 1 | 1 | | # do stuff |
|---|
| ... | |
|---|
| 2 | | - | return b'200 OK', [], ["Hello, World!"] |
|---|
| 2 | + | yield b'200 OK', [], ["Hello, World!"] |
|---|
| ... | |
|---|
| 3 | 3 | | |
|---|
| 4 | 4 | | def my_middelware(app): |
|---|
| 5 | 5 | | def wrapper(environ): |
|---|
| 6 | 6 | | # maybe edit environ |
|---|
| 7 | 7 | | try: |
|---|
| ... | |
|---|
| 8 | | - | status, headers, body = app(environ) |
|---|
| 8 | + | status, headers, body = yield app(environ) |
|---|
| ... | |
|---|
| 9 | 9 | | # maybe edit response: |
|---|
| 10 | 10 | | # body = (piglatin(data) for data in body) |
|---|
| 11 | 11 | | return status, headers, body |
|---|
| ... | |
|---|
| 16 | 16 | | |
|---|
| 17 | 17 | | def my_server(app, httpreq): |
|---|
| 18 | 18 | | environ = wsgi.make_environ(httpreq) |
|---|
| ... | |
|---|
| 19 | | - | try: |
|---|
| 19 | | - | status, headers, body = app(environ) |
|---|
| 19 | + | |
|---|
| 19 | + | def process_response(result): |
|---|
| 19 | + | status, headers, body = result |
|---|
| ... | |
|---|
| 21 | 21 | | write_headers(httpreq, status, headers) |
|---|
| ... | |
|---|
| 22 | | - | for data in body: |
|---|
| 22 | | - | write_data(httpreq, data) |
|---|
| 22 | | - | except: |
|---|
| 22 | | - | respond_with_500() |
|---|
| 22 | + | Coroutine(body, body_trampoline, finish_response) |
|---|
| 22 | + | |
|---|
| 22 | + | def finish_response(result): |
|---|
| 22 | + | # cleanup, if any |
|---|
| 22 | + | |
|---|
| 22 | + | Coroutine(app(environ), app_trampoline, process_response) |
|---|
| ... | |
|---|