Skip to content
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

Add Semaphore/Resource type #53

Open
maxfischer2781 opened this issue Sep 19, 2019 · 0 comments
Open

Add Semaphore/Resource type #53

maxfischer2781 opened this issue Sep 19, 2019 · 0 comments
Labels
enhancement New feature or request

Comments

@maxfischer2781
Copy link
Contributor

Porting SimPy resources (#51 and #50) made it pretty obvious that uSim's Resources type is a bit awkward when there really is just one type of resources.

resources = Resources(capacity=8)
await resource.increase(capacity=8)
await resource.decrease(capacity=8)
async with resource.borrow(capacity=8):
    ...

Other ways to emulate a Semaphore are Tracked and Queue, which come with other unwanted baggage. IMO the Resources interface is good, but we may want a "just one type" version:

resources = Resource(8)
await resource.increase(8)
await resource.decrease(8)
async with resource.borrow(8):
    ...

The use-case of a raw Semaphore would be easily handled by having proper defaults:

resources = Resource()  # default level of 0
await resource.increase()  # default in/decrease of 1
await resource.decrease()
async with resource.borrow():  # default borrow/claim of 1
    ...
@maxfischer2781 maxfischer2781 added the enhancement New feature or request label Sep 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant