Skip to content

Commit

Permalink
Implement yield "delay" => $milliseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Dec 2, 2023
1 parent d8677c8 commit 5fd004f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/main/php/xp/web/WebRunner.class.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace xp\web;

use Throwable;
use lang\ClassLoader;
use web\{Environment, Error, InternalServerError, Request, Response, Headers, Status};

Expand Down Expand Up @@ -79,13 +80,13 @@ public static function main($args) {

try {
$application= (new Source(getenv('WEB_SOURCE'), $env))->application();
foreach ($application->service($request, $response) ?? [] as $_) { }
foreach ($application->service($request, $response) ?? [] as $event => $arg) {
if ('delay' === $event) usleep($arg * 1000);
}
$env->logging()->log($request, $response);
} catch (Error $e) {
self::error($request, $response, $env, $e);
} catch (\Throwable $e) { // PHP7
self::error($request, $response, $env, new InternalServerError($e));
} catch (\Exception $e) { // PHP5
} catch (Throwable $e) {
self::error($request, $response, $env, new InternalServerError($e));
} finally {
$response->end();
Expand Down

0 comments on commit 5fd004f

Please sign in to comment.