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

catch error #5

Open
juchanhwang opened this issue Oct 23, 2020 · 1 comment
Open

catch error #5

juchanhwang opened this issue Oct 23, 2020 · 1 comment
Labels
question Further information is requested

Comments

@juchanhwang
Copy link

if i modify this code(in then() method)

super.then(
  value => onSettled("resolved", value, onFulfilled),
  reason => onSettled("rejected", reason, onRejected)
);

to

super
  .then( value => onSettled("resolved", value, onFulfilled))
  .catch( reason => onSettled("rejected", reason, onRejected))

my code occures this error
abortable-promise.ts:131 Uncaught (in promise) RangeError: Maximum call stack size exceeded

@dondevi
Copy link
Owner

dondevi commented Nov 22, 2020

You can't do that because they are different.

  • Rule 1: It creates a new Promise everytime you do .then, .catch (and .abort)
  • Rule 2: Internally super.catch(onRejected) will be this.then(undefined, onRejected)

Let’s say:

const promise = new AbortablePromise();
promise.then();  // Without this in your modify, it won't throw errors

- Case 1: super.then(onFulfilled, onRejected)

  1. promise.then
  2. new AbortablePromise
  3. super.then
  4. (End)

- Case 2: super.then(onFulfilled).catch(onRejected)

  1. promise.then
  2. new AbortablePromise
  3. super.then
  4. super.catch
  5. AbortablePromise.then (See Rule 2)
  6. new AbortablePromise
  7. super.then
  8. (Endless loop...)

@dondevi dondevi added the question Further information is requested label Nov 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants