Hello guys, I want to implement a simple request ...
# flow
s
Hello guys, I want to implement a simple request (a general request, not necessary an HTTP) handler where incoming requests are processed serially and in FIFO order. I need to provide an interface that notifies the caller when: 1) request processing has started (e.g., the request the caller submitted has been taken out of the queue and is about to be processed), and 2) the result of the request processing is available. Error observability is also required. The request type is specified by the type parameter. In my particular case request processing means bytes are written to a socket. More in the thread 🧵
I've created an implementation of such a request processor by using a dedicated channel that serves as a queue for requests and by creating a channel for every incoming request. The second channel allows me to notify the caller of the request's processing status. You can find the source code and tests covering the code below. Is this the right approach? Since this is a general concept often needed in applications, is there already a better solution for this? I need this processor to be able to limit the concurrency (to 1) of requests made to a remote resource, but also to abstract the caller from the FIFO queue implementation and maintain a "blocking" API (blocking in a way that I can immediately wait for processing results).
Untitled.cpp
Untitled.cpp