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

Monadic interface for object pools #6

Open
bignacio opened this issue Nov 25, 2022 · 0 comments
Open

Monadic interface for object pools #6

bignacio opened this issue Nov 25, 2022 · 0 comments

Comments

@bignacio
Copy link
Owner

Describe the feature you'd like
Add a monadic interface for handling obtaining objects from a pool

Additional context

Currently when a pool is empty - no items available - it's up to the user to write all the code and conditions to deal with that case.
Retrieving an object from the pool can also be a little expensive since it needs to be wrapped in a PoolItem object.

I propose an interface that would allow users to pass a lambda for each situation - item acquired or not (pool empty), something like

auto pool = dxpool::StaticPool<ItemType, 1>();

auto itemPresentLambda = [](ItemType& item){...}; 
auto poolEmptyLambda = [](){...};

pool
 .Get(itemPresentLambda).
 .OrElse(poolEmptyLambda();
  
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant