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

JarvisEmitter.promise can potentially settle multiple args #3

Open
KromDaniel opened this issue Feb 13, 2019 · 0 comments
Open

JarvisEmitter.promise can potentially settle multiple args #3

KromDaniel opened this issue Feb 13, 2019 · 0 comments

Comments

@KromDaniel
Copy link

JarvisEmitter.promise

promise() {
                // sorry for identation
		return new Promise((resolve, reject) => {
			this.done((...args) => {
				resolve(...args)
			});
			this.error((...args) => {
				reject(...args);
			});
			this.catch((...args) => {
				reject(...args);
			});
		});
	}

This have 2 issues:

  1. Resolve or reject more than a single argument
new Promise((resolve) => {
    resolve(5, 6, 7);
}).then((a, b, c) => {
    console.log(a, b, c); // 5, undefined, undefined
});
  1. Potentially can resolve/reject multiple times

1:

Maybe, same as bluebird, explicit say that promise can resolve more than a single argument:

promise(multiple = false) {
   return new Promise((resolve, reject) => {
       this.done((arg, ...rest) => {
           resolve(multiple ? [arg, ...rest] : arg);
       });

About rejection, I'm not sure what it means to reject multiple values, since reject is comparable to throw (and resolve compares to return)

2:
Is it possible that .error and .catch will emit together? potentially reject/resolve the same promise multiple times
Maybe before resolve or reject remove the listeners? or flag for if(!settled){ ... }

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