picqer / picqer-php

PHP Client for the Picqer API
https://picqer.com/en/api
MIT License
18 stars 23 forks source link

Add generator for large datasets #11

Closed barryvdh closed 5 years ago

barryvdh commented 6 years ago

By using yield, we can use the results directly, before waiting for the batch to finish. This helps reduce memory usage and reduces the rate of the request. Eg. load 100 results, process 1 by 1, load another 100 requests, process those etc.

It can still just be used in a foreach, without doing anything different.

casperbakker commented 6 years ago

This works like this, right?

foreach ($client->getResultsGenerator('product') as $product) {
   echo $product['idproduct'] . PHP_EOL;
}

Then I will add this to the documentation.

barryvdh commented 6 years ago

Yes, it only returns the product itself in the for each (no status or data object)

casperbakker commented 5 years ago

I have merged this and cleaned the code up a bit. Thanks @barryvdh