Skip to content
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

why lock udBeforeRequestLock and udBeforeRequestLock in execute #688

Closed
valiner opened this issue Aug 18, 2023 · 3 comments
Closed

why lock udBeforeRequestLock and udBeforeRequestLock in execute #688

valiner opened this issue Aug 18, 2023 · 3 comments

Comments

@valiner
Copy link

valiner commented Aug 18, 2023

func (c *Client) execute(req *Request) (*Response, error) {
	// Lock the user-defined pre-request hooks.
	c.udBeforeRequestLock.RLock()
	defer c.udBeforeRequestLock.RUnlock()

	// Lock the post-request hooks.
	c.afterResponseLock.RLock()
	defer c.afterResponseLock.RUnlock()

This looks very inefficient.

@valiner
Copy link
Author

valiner commented Aug 18, 2023

func (c *Client) OnAfterResponse(m ResponseMiddleware) *Client {
	c.afterResponseLock.Lock()
	defer c.afterResponseLock.Unlock()

	c.afterResponse = append(c.afterResponse, m)

	return c
}

OnAfterResponse is generally not used in http execute.

@jeevatkm
Copy link
Member

@valiner This PR would provide an insight #597

@jeevatkm
Copy link
Member

@valiner Also if you have a suggestion to improve, please mention it.

@valiner valiner closed this as completed Sep 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants