swisspol / GCDWebServer

The #1 HTTP server for iOS, macOS & tvOS (also includes web based uploader & WebDAV server)
Other
6.51k stars 1.25k forks source link

How to stream data in a serial mode? #557

Open ababo opened 3 years ago

ababo commented 3 years ago

When I create GCDWebServerStreamedResponse with asyncStreamBlock I end up with multiple threads simultaneously calling my handler. This is a bad scenario for me, since I want to process data and stream it sequentially (i.e. the order is important). This means I have to use NSLock or synchronise via single-threaded DispatchQueue which is far from an efficient implementation I would expect to achieve.

The ideal API would guarantee that my handler isn't called simultaneously in multiple threads. Alternatively I would like to use a synchronous streaming, when the request handler is called only once allowing me to call GCDWebServerBodyReaderCompletionBlock for multiple times, so I would call it in a loop while processing my data.

Can you clarify the way I should use GCDWebServer in my case?