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

Unpredictable search result #442

Open
mapogolions opened this issue Jan 20, 2020 · 0 comments
Open

Unpredictable search result #442

mapogolions opened this issue Jan 20, 2020 · 0 comments

Comments

@mapogolions
Copy link

mapogolions commented Jan 20, 2020

metatests.test('unpredictable search result', test => {
  const data = [{ name: 'Bob', age: 34 }, { name: 'Bob', age: 45 }];
  const expected = 34; // actual search result - 45
  const predicate = msec => {
    let delay = true;
    return (item, callback) => {
      if (delay) {
        delay = false;
        setTimeout(() => callback(null, item.name === 'Bob'), msec);
        return;
      }
      process.nextTick(() => callback(null, item.name === 'Bob'));
    };
  };

  metasync.find(data, predicate(200), (_, result) => {
    test.strictSame(result.age, expected);
    test.end();
  });
});
  1. Copy & past above snippet to the test/array.find.js
  2. Enter to the terminal npx metatests test/array.find.js
    In my opinion, method find should have sequential (series) semantics. Otherwise, we will obtain unpredictable search result depends on non deterministic delay of non-blocking operation
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