It would be great if the factory also exposed a a method that did the same thing as create()
just without registering side-effects, so it could be used as such:
function handle_request(\Closure $afterRequest) {
$treblle = TreblleFactory::onlyCreate($apiKey, $projectId);
set_error_handler($treblle->onError(...));
set_exception_handler($treblle->onException(...));
$afterRequest($treblle->onShutdown(...));
// do request
}
$running = true;
while($running) {
$later = [];
$afterRequest = static function ($callback) use (&$later) {
$later[] = $callback;
};
$running = frankenphp_handle_request(fn() => handle_request($afterRequest));
foreach($later as $cb) $cb();
}