-
Notifications
You must be signed in to change notification settings - Fork 13
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
feature: Adding option to use custom Id in request #277
Comments
Thanks @ivankhm for the issue! This is 100% something that we need to address. If you want to take a stab at a PR, feel free to take a stab. I've created another issue to track the 'custom id' function, as well as a flag to switch from string to number for the id's type, if you want to solve both, that would be sweet! |
Yeah I can see this being problematic, instantiate two clients to the same server, you have no way to manage the id's for those request, they're both listening for the same server responses. There's no way to coordinate between them. I could imagine this being as simple as abstracting id generation Logic as you suggest to some interface around interface RequestIDGenerator {
nextID(): int | string
}
function requestGenerator() {
let idCount = 0
return () => {
idCount = idCount + 1
return idCount;
}
} Where a simple closure can encapsulate some stateful data. I think you want the following at the end of the day. new GeneratedClient( options: {requestOptions: {nextId: ()=>number| string})
new Client(new RequestManager([transports],requestOptions)) Then we can have the behavior remain the same for people that don't care about that management. Additionally people using multiple clients can just lean on the same generator and won't hit that collision point around instantiating multiple clients. Let me know what you think or if this makes sense to y'all @BelfordZ @ivankhm |
@zcstarr yeah something like that. Though the generatedClient part will be done elsewhere, and the options should reference the classes by name, so more like For this specific part, we would just be adding, as you said, constructor options for RequestManager (along with exported RequestManagerOptions interface). The first constructor option being nextId function, and as highlighted in #279 , an option to use a number instead of a string if using the default nextId functionality |
This feature is to support generating requestID in either a string or numeric format. Additionally this will support multiple clients operating against the same context. The goal here is to allow systems like client generator to pass through this option to other downstream operators fixes #277 , fixes #279
This feature is to support generating requestID in either a string or numeric format. Additionally this will support multiple clients operating against the same context. The goal here is to allow systems like client generator to pass through this option to other downstream operators fixes #277 , fixes #279
This feature is to support generating requestID in either a string or numeric format. Additionally this will support multiple clients operating against the same context. The goal here is to allow systems like client generator to pass through this option to other downstream operators fixes #277 , fixes #279
This feature is to support generating requestID in either a string or numeric format. Additionally this will support multiple clients operating against the same context. The goal here is to allow systems like client generator to pass through this option to other downstream operators fixes #277 , fixes #279
🎉 This issue has been resolved in version 1.7.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Hello!
I think there should be a way to use a custom Id for the request. Besides, the current way can be unsafe, for example, if 2 clients simultaneously make the first request - they will have the same id, which can be confusing for a server.
I suggest passing a function into the constructor, that returns the next id, and using it in this method:
client-js/src/RequestManager.ts
Line 48 in 7909cd9
like this:
And initiate
this.getNextId
in the constructor via parameter or default value.The text was updated successfully, but these errors were encountered: