- if ($promise instanceof Promise) {
- $promise->when(function($error, $result) use($gen) {
- if ($error) {
- $gen->throw(exception($error));
- }
- if (($promise = $gen->send($result))) {
- $this->give($promise, $gen);
- }
- });
- } else {
- $gen->throw(new UnexpectedValueException(
- "Expected Promise or array of Promises; got ".\seekat\typeof($promise)));
- }
+
+ $this->future->handlePromise($promise, function($result) use($gen) {
+ if (($promise = $gen->send($result))) {
+ $this->give($promise, $gen);
+ }
+ }, function($error) use($gen) {
+ $gen->throw(exception($error));
+ });
+