prooph / pdo-event-store

PDO implementation of ProophEventStore http://getprooph.org
BSD 3-Clause "New" or "Revised" License
111 stars 56 forks source link

Use `count()` to support Generators #204

Closed sandrokeil closed 5 years ago

sandrokeil commented 5 years ago

Cannot rewind a generator that was already run.

See https://github.com/event-engine/php-engine/issues/6

I think we can use \count($data) here instead of \iterator_count($streamEvents) to support Generators. Any concerns?

arnedesmedt commented 5 years ago

I tried your solution already, but it will not work. Every $streamEvent generates 5 $data entries. See https://github.com/prooph/pdo-event-store/blob/master/src/PersistenceStrategy/PostgresSimpleStreamStrategy.php#L75-L90

So the result will be 5 if 1 streamEvent needs to persist.

arnedesmedt commented 5 years ago

According to: https://stackoverflow.com/a/22858509/919902

Generators are used to loop over them only once. A possible solution could be to count the streamEvents in the prepareData function and return the result of the count with the data array. But it's not a very neat solution.

What is the reason for using a Generator in event-engine/php-engine? Maybe that could be changed?

sandrokeil commented 5 years ago

Sorry, didn't checked this.