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

Improving generateId method #535

Merged
merged 9 commits into from
Oct 20, 2017
Merged

Improving generateId method #535

merged 9 commits into from
Oct 20, 2017

Conversation

efkan
Copy link
Contributor

@efkan efkan commented Oct 16, 2017

The kind of change this PR does introduce

  • a bug fix
  • a new feature
  • an update to the documentation
  • a code change that improves performance
  • other

Current behaviour

If overwritten and assigned generateId function needs some extra operation like Redis query, id value passed as undefined because Javascript runs asynchronously.

New behaviour

Adding a callback to generateId method provides the program flow to continue after a new generated id is provided.

Other information (e.g. related issues)

Also README file has been changed according to the updates above.

Adding a callback to generateId method provides the program flow to continue after a new generated id is provided.
Adding callback to generateId method
lib/server.js Outdated
Server.prototype.generateId = function (req) {
return base64id.generateId();
Server.prototype.generateId = function (req, callback) {
callback(base64id.generateId());
Copy link
Member

Choose a reason for hiding this comment

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

How about callback(null, base64id.generateId());, so that errors can also be handled (see #518)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right! I'll update the code.

@darrachequesne darrachequesne merged commit 2abb217 into socketio:master Oct 20, 2017
@darrachequesne
Copy link
Member

@efkan merged, thanks!

@darrachequesne darrachequesne added this to the 4.0.0 milestone Oct 20, 2017
darrachequesne added a commit that referenced this pull request Feb 27, 2018
That is a breaking change, which mandates a major bump.
@efkan
Copy link
Contributor Author

efkan commented Mar 7, 2018

Hello @darrachequesne ,

I've seen that this PR had to be reverted.

[revert] Make generateId method async
That is a breaking change, which mandates a major bump.

I could not find any issue about it.
I was wondering that what is the breaking change and is there anything I can do to help on this?

@darrachequesne
Copy link
Member

@efkan I'm currently working on releasing a new version of socket.io, but yes both of your propositions (async generateId and #538) should be included in version engine.io@4.0.0, sorry for the delay.

@efkan
Copy link
Contributor Author

efkan commented Mar 7, 2018

@darrachequesne , Do you want me to apply my code again on a new PR?

@darrachequesne
Copy link
Member

@efkan I'll cherry-pick it.

@ghost
Copy link

ghost commented Jul 27, 2018

Can we make this support Promises (async functions) as well as callbacks?

This pull request was closed.
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.

2 participants