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

Consider exposing more from builder #11

Open
withinboredom opened this issue Apr 2, 2024 · 0 comments
Open

Consider exposing more from builder #11

withinboredom opened this issue Apr 2, 2024 · 0 comments

Comments

@withinboredom
Copy link

withinboredom commented Apr 2, 2024

Trebble factory exposes a single method: create() which is great when using SAPIs that support shutdown functions :) but causes a memory leak when the SAPI doesn't support shutdown functions. For example, FrankenPHP (disclosure: I'm a contributor on the project), doesn't support shutdown functions.

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