unsplash / unsplash-php

👻 Official PHP wrapper for the Unsplash API
MIT License
415 stars 74 forks source link

Download endpoint not called async #80

Closed roelvanduijnhoven closed 6 years ago

roelvanduijnhoven commented 6 years ago

In the medium post I read:

We’ve found that it’s best to trigger the endpoint asynchronously to make sure that it doesn’t slow down your user’s interactions.

However the download endpoint is not async. See: https://github.com/unsplash/unsplash-php/blob/master/src/Photo.php#L204. In fact: it has a return value. Thus if I would add this call; this would now indeed slow down the user experience a little bit.

Is the behaviour in this repo intended? I would suggest introducing a new method asyncDownload that does precisely that. We could use Guzzle's async mechanism: http://docs.guzzlephp.org/en/stable/faq.html#can-guzzle-send-asynchronous-requests.

lukechesser commented 6 years ago

This is the intended behaviour currently. We could definitely add an async download method though — I'm open to it.

In the API Guidelines, we're more referring to the fact that we've found that it's best to call it async, but we didn't prescribe that in the library, because there are lots of ways to make an async call, like using workers or relying on the download call being made client-side.

roelvanduijnhoven commented 6 years ago

Thanks @lukechesser

roelvanduijnhoven commented 6 years ago

Gave it a go, but in the end this cannot be done properly using PHP. https://github.com/guzzle/guzzle/issues/1127