Proposal to Simplify Get
API by Returning a Pointer and Automating Resource Management
#4294
Labels
Get
API by Returning a Pointer and Automating Resource Management
#4294
Subject: Proposal to Simplify
Get
API by Returning a Pointer and Automating Resource ManagementDear Pebble Developers,
I would like to propose an improvement to the
Get
API to simplify its usage and prevent resource leaks.Current Issue:
The
Get
method currently returns a value, acloser
, and an error, which requires the user to explicitly callcloser.Close()
. This complicates the code and can lead to resource leaks if the developer forgets to callClose
.Proposal:
Modify the
Get
method to return a pointer to an object that automatically manages its resources. For example:Benefits:
Close
.Implementation:
This can be achieved using
runtime.SetFinalizer
or wrapper types that automatically close resources. For example:Alternatively, a wrapper type can be used:
Why This Matters:
Close
is a common source of bugs, and this change eliminates that risk.database/sql
in Go) already handle resource management internally, making this a familiar pattern for developers.Conclusion:
This change would make the Pebble API more intuitive, reliable, and consistent with modern Go libraries. I believe it would greatly improve the developer experience and reduce the likelihood of resource leaks.
Jira issue: PEBBLE-334
The text was updated successfully, but these errors were encountered: