-
Notifications
You must be signed in to change notification settings - Fork 53
feat: add AsyncSemaphore #586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: Jacek Sieka <[email protected]>
|
I'm sorry, but could you please explain why your Semaphore implementation requires |
this is semaphore from libp2p. this pr is adding it here so that it could be reused. it was implemented way before i joined the project so detailed reasoning i am not able to answer.
|
Semaphore from Also as you can see here present alternative AsyncSemaphore implementation #147. As a compromise i would propose to make some fields in |
👍 |
the use case is the following: a semaphore is used to control whether tcp without forceacquire one would have to adjust the upper limit and then down again which seems like the more complex solution. |
|
i have removed still from my perspective, there isn't anything hacky with please let me know how do we want to proceed with this. |
|
I have checked So if you want your own specific version of |
|
@arnetheduck @cheatfate is there a concensus on this? |
it just occured to me that libp2p can simply |
haha that's smart actually. or even |
consider that you have a limit of 6 connections and you want to maintain a balance of incoming and outgoing connections - in this case, if you have 6 connections already but they're all incoming, you want to start making outgoing connections without allowing incoming connections - iff some of those outgoing connections are successful, you can drop the "least useful" incoming connection and bring back balance, but you only know that at the end of the "outgoing attempt". In the above example, you can make as many parallel outgoing attempts as you like, but for the sake of simplicity, let's assume 1. While you're "attempting", you should continue to not allow incoming connections - ie if you start a connection attempt and 1 connection drops, you still don't want to allow more incoming connections - however, if 2 connections drop, you can allow one incoming (since the incoming + the outgoing attempt won't exceed 6 together). This last bit is why we count all connections but "force" outgoing connections: because we have other mechanisms to control how many outgoing connections we make, while the limit is on outgoing+incoming and the incoming connections keep coming without us controlling when and how many. |
Co-authored-by: Jacek Sieka <[email protected]>
Co-authored-by: Jacek Sieka <[email protected]>
Co-authored-by: Jacek Sieka <[email protected]>
No description provided.