[FEATURE] adds InitChan() to create a chan generator #7
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.
Hi @nrednav
I was having a look at your port, and saw the use of
sync/atomicfor the session counter.I figured this could be a bottleneck for use cases where a lot of Cuids need to be generated by several goroutines.
The proposition is to add an
InitChan()func which returns a channel from which cuids can be received.The buffer size of the channel can be configured, and defaults to 10.
InitChan()also returns a cancel function, which stops the generation of new Cuids.A specific
Contextcan also be configured (e.g. an HTTP request Context), which will stop the generation as soon as theContextis done.What do you think?
Feel free to make the changes you want to or tell me what changes would be necessary to merge this.
Cheers!