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

Always use a fresh iterator #5

Merged
merged 1 commit into from
Mar 18, 2019

Conversation

sebald
Copy link
Contributor

@sebald sebald commented Mar 8, 2019

In 2.0 there was a regression introduced regarding the reusability of the pipe.

const pipe = require('p-pipe');

const fn = () => 'whoops';
const task = pipe(fn);

const t1 = await task(); // returns 'whoops'
const t2 = await task(); // returns undefined

This was caused by not resetting the iterator. Every subsequent use of the task was reusing the same iterator, which already finished iterating in the first usage 🤦‍♂️

This patch will make sure a fresh iterator is created on every usage of the task.

Also added a test to make sure this is not happening again!

Fixes #6

@sebald sebald changed the title Always use a fresh iterator. Fix: Always use a fresh iterator. Mar 16, 2019
@johnmaia
Copy link

johnmaia commented Mar 18, 2019

@sindresorhus would appreciate if you could take a look at this PR and release a 🌈 new version 🦄.

@sindresorhus sindresorhus changed the title Fix: Always use a fresh iterator. Always use a fresh iterator Mar 18, 2019
@sindresorhus sindresorhus merged commit 5a49270 into sindresorhus:master Mar 18, 2019
sindresorhus pushed a commit that referenced this pull request Mar 18, 2019
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

Successfully merging this pull request may close these issues.

3 participants