You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My goal is to have an endpoint that will accept a post body and then basically send incremental chunks of data as we complete the processing.
I found a couple ways to do, here is a mock'd example where I would return the controller.stream immediately and then process the chunks in the background incrementally send then as they finish.
Future<Response> _echoRequest(Request request) async {
var controller =StreamController<List<int>>();
// Start an async task to send chunksFuture(() async {
for (int i =0; i <10; i++) {
// Send size of the chunk in hexadecimal followed by CRLF
controller.add('${'Chunk $i'.length.toRadixString(16)}\r\n'.codeUnits);
// Send the chunk followed by CRLF
controller.add('Chunk $i\r\n'.codeUnits);
// Delay to simulate processingawaitFuture.delayed(Duration(seconds:1));
}
// Final chunk (size 0) followed by CRLF, and then end with another CRLF
controller.add('0\r\n\r\n'.codeUnits);
controller.close();
});
returnResponse(200, body: controller.stream, headers: {
'Transfer-Encoding':'chunked',
'Content-Type':'text/plain',
});
}
I found, however that the chunks don't send over to the client untill the controller has been fully closed.
I'm wondering if I'm doing something wrong here and was wondering if you all could help me out.
Another solution that I know will work is just default to websockets, but figured I would ask anyways.
Thanks,
Mark
The text was updated successfully, but these errors were encountered:
Hey all,
First, thank you for the wonderful Dart package!
My goal is to have an endpoint that will accept a post body and then basically send incremental chunks of data as we complete the processing.
I found a couple ways to do, here is a mock'd example where I would return the controller.stream immediately and then process the chunks in the background incrementally send then as they finish.
I found, however that the chunks don't send over to the client untill the controller has been fully closed.
I'm wondering if I'm doing something wrong here and was wondering if you all could help me out.
Another solution that I know will work is just default to websockets, but figured I would ask anyways.
Thanks,
Mark
The text was updated successfully, but these errors were encountered: