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

feat: switch to native Promise #624

Closed

Conversation

alexkvak
Copy link

@alexkvak alexkvak commented May 6, 2021

No description provided.

@kibertoad
Copy link
Collaborator

@alexkvak This needs to be synced with master after old Node versions were dropped

return self.closeBecause("Goodbye", defs.constants.REPLY_SUCCESS,
cb);
});
// return new Promise(function(resolve, reject) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be commented out?

Copy link
Author

Choose a reason for hiding this comment

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

I need some help with this.

If I replace Bluebird.fromCallback with commented code it seems that channel.accept is called after this promise resolved. So the behavior changes and I have no idea why. I'm sure you have more context with this.

@@ -74,10 +98,16 @@ C.open = function() {

C.close = function() {
var self = this;
return Promise.fromCallback(function(cb) {

return Bluebird.fromCallback(function(cb) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Am I misunderstanding something, or promisify could be used here instead of Bluebird?

Copy link
Author

Choose a reason for hiding this comment

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

After dropping old Node version — it could

Copy link
Collaborator

Choose a reason for hiding this comment

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

Only Node 10+ is supported in master, so should be fine to use it now.

Copy link
Author

Choose a reason for hiding this comment

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

Replaced with util.promisify

Copy link
Author

Choose a reason for hiding this comment

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

btw .travis.yml in main still builds library for old Node.js versions

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, I think it was just missed in 267dd4e. Probably Travis needs to be adjusted to only test for Node 10+ as well.

@alexkvak alexkvak force-pushed the feat/switch-to-native-promise branch from 58d9bab to 1e59be1 Compare May 18, 2021 08:46
Copy link
Author

@alexkvak alexkvak left a comment

Choose a reason for hiding this comment

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

@alexkvak This needs to be synced with master after old Node versions were dropped

Done

return self.closeBecause("Goodbye", defs.constants.REPLY_SUCCESS,
cb);
});
// return new Promise(function(resolve, reject) {
Copy link
Author

Choose a reason for hiding this comment

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

@squaremo could you help with those three places (lines 106, 203 and 243)

If I replace Bluebird.fromCallback with commented code it seems that channel.accept is called after this promise resolved. So the behavior changes and I have no idea why. I'm sure you have more context with this.

self._rpc(defs.BasicConsume, fields, defs.BasicConsumeOk, cb);
})
// return new Promise(function(resolve, reject) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be commented out?

@@ -5,7 +5,6 @@
'use strict';

var defs = require('./defs');
var Promise = require('bluebird');
var inherits = require('util').inherits;
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated to this PR but i just notices inherits, NodeJS docs mention discourage use of inherits and that class extends should be used instead.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'll open PR for this

@KristjanTammekivi
Copy link

Should also edit the types once this is ready https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/amqplib

@@ -1,15 +1,10 @@
var raw_connect = require('./lib/connect').connect;
const { promisify } = require('util');
const raw_connect = promisify(require('./lib/connect').connect);
Copy link
Contributor

Choose a reason for hiding this comment

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

promisify is undefined

@xamgore
Copy link
Contributor

xamgore commented May 31, 2021

I don't really recommend changing anything until tests are being migrated to jest and a proper memory leak detector is set up. There is a PR that fixes a memory leak, though either it isn't covered by tests or mocha's detector can't catch the case. Anyway, any change in the codebase may bring undesired behavior in the future, and it may take time to fix and release it. As I may see in the comments here, Bluebird's semantics differs a bit from Node's promise implementation.

Also, @squaremo is quite a busy man and merges PRs if only 100% sure they are ok. I'm going to send a PR with jest migration this week.

@carlhoerberg
Copy link
Contributor

https://github.com/cloudamqp/amqp-client.js/ is a modern zero dependency AMQP library, implementing native promises, among other improvements.

@alexkvak
Copy link
Author

https://github.com/cloudamqp/amqp-client.js/ is a modern zero dependency AMQP library, implementing native promises, among other improvements.

Thanks a lot! I'll take a look and return with feedback 👍

@mohd-akram
Copy link
Contributor

Use of native promises has been released in v0.10.0 via #689. This can be closed.

@cressie176 cressie176 closed this Jun 5, 2022
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

Successfully merging this pull request may close these issues.

8 participants