Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot rewind a generator that was already run #6

Closed
arnedesmedt opened this issue May 16, 2019 · 3 comments
Closed

Cannot rewind a generator that was already run #6

arnedesmedt opened this issue May 16, 2019 · 3 comments

Comments

@arnedesmedt
Copy link
Contributor

Hi,

Thx for the new event machine v2!

I was implementing the event engine tutorial (https://event-engine.io/tutorial/) but I'm stuck on an exception thrown in the postgresql event store: It throws 'Cannot rewind a generator that was already run': https://github.com/prooph/pdo-event-store/blob/master/src/PostgresEventStore.php#L194-L200

The error is thrown at line 200. But the problem is that the iterator (here the Generator) is looped in the prepareData function and rewinded in the \iterator_count function. And that throws the exception. See https://www.php.net/manual/en/generator.rewind.php

Is there a workaround for preventing this error?

Thx in advance,

Arne

@codeliner
Copy link
Contributor

codeliner commented May 20, 2019

Hey @arnedesmedt , thx for reporting the bug. It's my fault. I've tried to fix an issue with the MapIterator of the php-engine-utils package. We recognized a problem when using the MapIterator with a MongoDB cursor, so I've refactored it to use a Generator internally. Unfortunately, I've forgotten that Generators are not rewindable :(

In our current project we use Event Engine with a custom MongoDB store (not open source yet) and the fix worked for us but I did not test it with prooph v7 PDO Event Store :(

Fix

Run composer update. It should install the new php-engine-utils release v0.1.4.

Can you try again with the new version?

Sorry for the problems. I already discussed with @sandrokeil that we will write a test suite that goes through the tutorial and ensures it's working when we release a new version of a package.

@arnedesmedt
Copy link
Contributor Author

Thank you very much for the fix. It works now!

@codeliner
Copy link
Contributor

great! Hopefully you can enjoy the rest of the tutorial without strange bugs ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants