Hi,

Guzzle's requestAsync() returns a promise, it does not
> interrupt/suspend the callsite. For example:
>
>     // this function is not interrupted/suspended -- it will return
> synchronously
>     function doSomething() {
>         $this->guzzle->requestAsync(...)->then(... handle response here
> ...);
>         echo "This will be printed before a response is received";
>     }
>
> The following is similar to how one would implement an coroutine in
> PHP today when using a library which implements a coroutine mechanism,
> such as amphp. Note the yield statement which interrupts/suspends the
> function:
>
>     // this function will be suspended while the request is in flight
> -- it will return after a response is received
>     function doSomething()
>         $response = yield $this->guzzle->requestAsync(...);
>         // do something with response here
>         echo "This will be printed AFTER the response comes back";
>     }
>
> Note the difference between the two. Also note how, in both of the
> above cases, the asynchronicity is explicit and the developer has
> opted into it. Both of the above are different approaches to that
> being proposed in this RFC (this is a design choice by the authors).
>

At the risk of sounding dumb: What would that code look like with fibers?

Thanks,

-- 
Guilliam Xavier

Reply via email to