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

The README.md example does not work with node.js v14 #1

Open
crguezl opened this issue Dec 27, 2020 · 0 comments
Open

The README.md example does not work with node.js v14 #1

crguezl opened this issue Dec 27, 2020 · 0 comments

Comments

@crguezl
Copy link

crguezl commented Dec 27, 2020

Thanks for the module. Looks interesting!

However, I can make it work.
When executing the provided example:

import raceIterator from './racing-for-await-of/index.js';

// See https://stackoverflow.com/questions/40920179/should-i-refrain-from-handling-promise-rejection-asynchronously
process.on('rejectionHandled', () => {});
process.on('unhandledRejection', error => {
  console.log('unhandledRejection');
});

const sleep = time => new Promise(resolve => setTimeout(resolve, time));

(async function () {
    const arr = [
        sleep(2000).then(() => 'a'),
        'x',
        sleep(1000).then(() => 'b'),
        'y',
        sleep(3000).then(() => 'c'),
        'z',
    ];

    for await (const item of raceIterator(arr)) {
        console.log(item);
    }
}());

It outputs:

➜  test-racing-for-await-of git:(master) ✗ node --version
v14.4.0
➜  test-racing-for-await-of git:(master) ✗ node hello-racing-for-await-of.js
unhandledRejection
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

1 participant