Improving generateId method#535
Merged
darrachequesne merged 9 commits intosocketio:masterfrom Oct 20, 2017
Merged
Conversation
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()); |
Member
There was a problem hiding this comment.
How about callback(null, base64id.generateId());, so that errors can also be handled (see #518)?
Contributor
Author
There was a problem hiding this comment.
You're right! I'll update the code.
Member
|
@efkan merged, thanks! |
5 tasks
darrachequesne
added a commit
that referenced
this pull request
Feb 27, 2018
That is a breaking change, which mandates a major bump.
Contributor
Author
|
Hello @darrachequesne , I've seen that this PR had to be reverted. I could not find any issue about it. |
Member
Contributor
Author
|
@darrachequesne , Do you want me to apply my code again on a new PR? |
Member
|
@efkan I'll cherry-pick it. |
9 tasks
|
Can we make this support Promises (async functions) as well as callbacks? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The kind of change this PR does introduce
Current behaviour
If overwritten and assigned
generateIdfunction needs some extra operation like Redis query,idvalue passed as undefined because Javascript runs asynchronously.New behaviour
Adding a callback to
generateIdmethod 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.