Answer the question
In order to leave comments, you need to log in
How to implement a pull?
I want to implement a pull. It came to mind to make a map with connections and make a counter of "open connections". After the connection, add the connection to the pool. When reusing it, remove it from the map (without touching the counter), and as soon as it is released, return it to the map. And from the map, pull the connection randomly. If there are no free connections, then check how many connections there are (counter value) and if they are less than the maximum available, then create a new one. Otherwise, we throw it into the queue (if you please, add a description of the queue logic to the answers)
I don't need the code. I want to know if my thinking is correct.
Answer the question
In order to leave comments, you need to log in
I 'm sorry,
then I'll just add that
old connections need (can) be removed,
take into account calls from different streams.
If the limit is reached, it is possible to block the call or return fail
Why random choice - there is no need.
Additional checks for code correctness, accounting for double returns.
Ideally, a return could be done in a destructor or an analogue in this language, defer or whatever
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question