-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent cancellation from propagating to background request context (#17
) * Failing test for issue #16 * Cancellation does not propagate to background request context * Updating test description
- Loading branch information
1 parent
b6ab5e1
commit 485a0fc
Showing
3 changed files
with
101 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package microcache | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
) | ||
|
||
// newBackgroundRequest clones a request for use in background object revalidation. | ||
// This prevents a closed foreground request context from prematurely cancelling | ||
// the background request context. | ||
func newBackgroundRequest(r *http.Request) *http.Request { | ||
return r.Clone(bgContext{r.Context(), make(chan struct{})}) | ||
} | ||
|
||
type bgContext struct { | ||
context.Context | ||
done chan struct{} | ||
} | ||
|
||
func (c bgContext) Done() <-chan struct{} { | ||
return c.done | ||
} |
This file contains 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
This file contains 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