Repository navigation
(feat) Application: Go-style defer() for guaranteed cleanup - #365
Conversation
techmahedy
left a comment
There was a problem hiding this comment.
as per my check, this PR is ok @NazmusShakib @abdulmajidcse @rrr63
|
Please preserve exceptions thrown by Currently, Please capture the terminating exception, pass it to Also, the PR states that |
@abdulmajidcse docs page: https://github.com/doppar/docs/blob/41923567f2b98d8d8b2b8a624484eb9e72af75c1/versions/4.x/defer.md |
|
@abdulmajidcse please check now "Please preserve exceptions thrown by terminating() callbacks when reporting deferred cleanup failures." about this issue |
Pull Request Checklist
Problem (solution of this issue )
Code that acquires a temporary resource (a cache lock, a file handle, a temp file, a tracing span, a transaction) had to manage its cleanup by hand, or know which lifecycle hook runs late enough to be safe.
terminating()is application-wide and registered once at boot, so it does not express local resource ownership, and its ordering is registration order.Solution
defer()registers a callback that runs when the current execution ends, after success or after an exception, in last-in-first-out order.Available as
app()->defer(),App::defer()and thedefer()helper.Semantics
logservice;reportDeferredExceptionsUsing()overrides this.defer()outside an active scope throws aLogicException. There is no implicit application-lifetime fallback.Lifecycle adapters
All adapters share one implementation (
DeferScopeplus the scope methods onApplication).dispatch()DispatchResult::terminate(), afterterminating()callbacks and before request-scoped services are dropped; immediately if handling or error rendering throwsConsole::doRunCommand()app()->runInDeferScope($callback)Checklist