Skip to content

Commit

Permalink
Forward thrown exceptions to loop
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Aug 23, 2016
1 parent 214816f commit 1202299
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/BodyParser.php
Expand Up @@ -3,6 +3,7 @@
namespace Aerys;

use Amp\{ Coroutine, Deferred, Internal\Placeholder, Observable, Postponed, Success };
use Interop\Async\Loop;

class BodyParser implements Observable {
use Placeholder;
Expand Down Expand Up @@ -71,7 +72,13 @@ public function __construct(Request $req, array $options = []) {
foreach ($result->getNames() as $field) {
foreach ($result->getArray($field) as $_) {
foreach ($this->subscribers as $watcher) {
$watcher($field);
try {
$watcher($field);
} catch (\Throwable $e) {
Loop::defer(static function () use ($e) {
throw $e;
});
}
}
}
}
Expand Down Expand Up @@ -231,7 +238,13 @@ private function initField($field, $metadata = []) {
}

foreach ($this->subscribers as $watcher) {
$watcher($field);
try {
$watcher($field);
} catch (\Throwable $e) {
Loop::defer(static function () use ($e) {
throw $e;
});
}
}

return $dataPostponed;
Expand Down

0 comments on commit 1202299

Please sign in to comment.