3 ms·
Now do a body that requires literally any transformation or generation at all. Say, a series of DB query results as a CSV. (Oh, and make sure to cancel work whe
by morelisp 4y ago
Now do a body that requires literally any transformation or generation at all. Say, a series of DB query results as a CSV. (Oh, and make sure to cancel work when the request disconnects!)
Or heck, just try adding some error handling from the `io.Copy` result to what you have.
- suremarc 4y agoJust return an io.Reader that wraps the DB cursor and outputs CSV data... I fail to see what makes this so difficult. If the "mutable" approach involves passing down a mutable *http.ResponseWriter, then the dual approach of passing an io.Reader upstream is equivalent.
- int_19h 4y agoThis all is much more straightforward in languages with syntactic sugar for iterators, such as "yield" in C# and Python: https://flask.palletsprojects.com/en/2.2.x/patterns/streaming/ https://flask.palletsprojects.com/en/2.2.x/patterns/streamin...
- morelisp 4y agoLove too make those async thunks!
- morelisp 4y agoTry to write this, really. It’s such an unergonomic mess compared to for loop in the handler. It will also allocate a very complex reader that the actual version doesn’t need to.