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

Unexpected raising error sequence #404

Open
xareelee opened this issue Jan 29, 2017 · 2 comments
Open

Unexpected raising error sequence #404

xareelee opened this issue Jan 29, 2017 · 2 comments

Comments

@xareelee
Copy link

xareelee commented Jan 29, 2017

I try to use Most.js instead of RxJS.

The following code obtains an unexpected result:

import * as Most from 'most';


function asyncReject() {
  return new Promise((_, reject) =>
    reject(new Error('Error getting asyncReject'))
  );
}

function asyncRawReject() {
  return Promise.reject('Error getting asyncRawReject');
}

function asyncError() {
  return new Promise(() => {
    throw new Error('Error getting asyncError');
  });
}

function asyncRawError() {
  return new Promise(() => {
    /* eslint-disable */
    throw 'Error getting asyncRawError';
    /* eslint-enable */
  });
}

function asyncReturnError() {
  return Promise.resolve(new Error('Error getting asyncReturnError'));
}

// We will execute those Promises in the sequence
const promiseExecutors = [
  asyncReject,
  asyncRawReject,
  asyncError,
  asyncRawError,
  asyncReturnError
]

const streams = promiseExecutors.reduce((collection, executor) => {
  const promise = executor();
  const stream = Most.fromPromise(promise)
    .flatMap(x => {
      if (x instanceof Error) {
        return Most.throwError(x);
      }
      return Most.of(x);
    });
  return collection.concat(stream);
}, []);

const combined = Most.combineArray((...values) => [ ...values ], streams);

combined.subscribe({
  next: (x) => console.log('[next]:', x),
  error: (err) => console.log('[error]:', err.message ? err.message : err),
  complete: () => console.log('[complete]'),
})

// Results:
// [error]: Error getting asyncReturnError        // => should be the last
// [error]: Error getting asyncReject
// [error]: Error getting asyncRawReject
// [error]: Error getting asyncError
// [error]: Error getting asyncRawError

// Expected (the same as the sequence in the executors):
// [error]: Error getting asyncReject
// [error]: Error getting asyncRawReject
// [error]: Error getting asyncError
// [error]: Error getting asyncRawError
// [error]: Error getting asyncReturnError

I'll get asyncReturnError first as unexpected. It seems that the error events from Promise in Most.js are not synchronous.

When I use RxJS, I can get the errors in the same sequence as the executors, but not when using Most.js.

How can I fix this if it is not a bug?

@davidchase
Copy link
Collaborator

hi @xareelee,

When i tested your issue in the webpackbin, I noticed that the asyncReturnError was being resolved rather than rejected is that expected ?

If i change it to reject similar to your other error functions you get your expected results http://www.webpackbin.com/V1_lYi5Yf

@xareelee
Copy link
Author

xareelee commented Mar 1, 2017

hi @davidchase ,

This test case is obtained from graphql-js. The error is expected to be resolved.

I'm trying to replace the Promise-based execute() with Observable-based (like most.js), and this is the one failed test case.

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