Feat: Add the PagePool.TryGet method while it returns an error for processing. #1051
Merged
ysmood merged 7 commits intogo-rod:mainfrom May 6, 2024
Merged
Feat: Add the PagePool.TryGet method while it returns an error for processing. #1051ysmood merged 7 commits intogo-rod:mainfrom
ysmood merged 7 commits intogo-rod:mainfrom
Conversation
ysmood
reviewed
May 5, 2024
| } | ||
|
|
||
| // TryGet a page from the pool, allow error. Use the [PagePool.Put] to make it reusable later. | ||
| func (pp PagePool) TryGet(create func() (*Page, error)) (*Page, error) { |
Member
There was a problem hiding this comment.
Suggested change
| func (pp PagePool) TryGet(create func() (*Page, error)) (*Page, error) { | |
| func (pp PagePool) Get(create func() (*Page, error)) (*Page, error) { |
Could you help to rename the Get to MustGet? Same for the browser pool.
Contributor
Author
There was a problem hiding this comment.
I've tried it before, but MustGet is restricted to be implemented in must.go because of the lint.
Changing to PagePool.Get also could involve the chrome-extensions. I'll rename it if these changes don't impact a lot.
Member
There was a problem hiding this comment.
Sure, move the MustGet to must.go file. Keep your Get one in the utils.go file.
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.
Development guide
Link
Test on local before making the PR
PagePool Change
The
PagePool.Getcan now only acceptcreate func() *Pageas input, so there is no way to output the error that may exist in the create func other than using a closure or using recover, and it is inconvenient for users in a multi-routine environment to perform logical processing based on the actual error that occurred. I added thePagePool.MustGetmethod to solve this. However, I'm not sure whether this change would be in line with the original design.Besides,
PagePool.CleanUpmay stuck whileppis not full (forget/panic to Put, etc). I also think this might be an issue when using PagePool. Useselectto prevent stucking