Skip to content

Consider exposing more from builder #11

@withinboredom

Description

@withinboredom

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions