-
-
Notifications
You must be signed in to change notification settings - Fork 356
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
Feat: Add the PagePool.TryGet method while it returns an error for processing. #1051
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏼
utils.go
Outdated
@@ -101,6 +101,15 @@ func (pp PagePool) Get(create func() *Page) *Page { | |||
return p | |||
} | |||
|
|||
// 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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, move the MustGet to must.go file. Keep your Get
one in the utils.go file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Development guide
Link
Test on local before making the PR
PagePool Change
The
PagePool.Get
can now only acceptcreate func() *Page
as 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.MustGet
method to solve this. However, I'm not sure whether this change would be in line with the original design.Besides,
PagePool.CleanUp
may stuck whilepp
is not full (forget/panic to Put, etc). I also think this might be an issue when using PagePool. Useselect
to prevent stucking