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

fix(connection): openUri return promise-like on existing connection #9358

Closed
wants to merge 4 commits into from
Closed
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/connection.js
Expand Up @@ -669,6 +669,12 @@ Connection.prototype.openUri = function(uri, options, callback) {
if (typeof callback === 'function') {
callback(null, this);
}

this.then = (resolve) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.then = (resolve) => {
this.then = (resolve) => {
delete this.then;
delete this.catch;
resolve(this);
return this
}

if you don't do this, if you try to call Promise.resolve(conn) or await conn your interpreter will go in an infinite loop of calling resolve recursively as it tries to flatten the promise, see #8810

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes, sense, fixed! However in this way, it's not possible to do conn.openUri(...).then().catch()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess if you really wanted to you could do

this.then = (resolve) => {
  process.nextTick(() => {
    delete this.then;
    delete this.catch;
    resolve(this);
  });
  return this;
}

resolve(this);
return this;
};
this.catch = () => {};
return this;
}

Expand Down