Skip to content

Monadic interface for object pools #6

@bignacio

Description

@bignacio

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();
  

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions