Golang http write response without waiting to finish

后端 未结 3 1667
后悔当初
后悔当初 2021-01-29 08:35

I\'m building an application that builds a pdf file and returns it to the client whenever it receives a request.

Since some of these pdf files might take some time to g

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-29 09:15

    TL;DR is that it cannot be implemented that way. You need to

    1. An API that requests the PDF creation. That queues PDF creation job in a task queue (so that too many PDF creation requests won't blow the HTTP server worker pool)
    2. Provide an API that allows you to check where are you with the PDF rendering (I am assuming that the job can provide interim stats). This is going to be polled by the client on a regular basis.
    3. An API to pull the PDF once it is ready.

    Hope this helps and best of luck with your project.

提交回复
热议问题