- From: Alex Darby <notifications@github.com>
- Date: Mon, 08 May 2023 04:28:30 -0700
- To: whatwg/fetch <fetch@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Monday, 8 May 2023 11:28:36 UTC
Hey! Thanks for the reply - sever code is below. It's a very simple Flask app in Python that gives results like this:
```json
{
"items": [
{
"hello": "world"
},
...
{
"hello": "world"
}
]
}
```
To be clear, it does stop reading when it's reached the 2000them item. But I'm looking for a way to pause and resume it any arbitrary point in the stream.
```python
import json
from flask import Flask, Response
from flask_cors import CORS
app = Flask(__name__)
CORS(app)
@app.route('/')
def entry_point():
def my_generator():
yield '{"items": ['
for count in range(1, 2001):
my_json_object = json.dumps({"hello": "world"})
if count == 2000:
yield my_json_object
else:
yield my_json_object + ", "
yield ']}'
return Response(my_generator(), status=200, content_type='application/json')
if __name__ == '__main__':
app.run(debug=True)
```
--
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/issues/1651#issuecomment-1538206160
You are receiving this because you are subscribed to this thread.
Message ID: <whatwg/fetch/issues/1651/1538206160@github.com>
Received on Monday, 8 May 2023 11:28:36 UTC