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
package main | |
import ( | |
"fmt" | |
"net/http" | |
"net/http/httptest" | |
"time" | |
) | |
func Example_limitHandlerExecutionTime() { |
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
package main | |
import ( | |
"context" | |
"fmt" | |
"net" | |
"net/http" | |
"net/http/httptest" | |
) |
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
package main | |
import ( | |
"errors" | |
"fmt" | |
"io" | |
"net" | |
"net/http" | |
"net/http/httptest" | |
) |
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
package main | |
import ( | |
"context" | |
"fmt" | |
"regexp" | |
"time" | |
) | |
func Example_contextHierarchy() { |
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
package main | |
import ( | |
"context" | |
"fmt" | |
"runtime" | |
) | |
type myCtx struct { | |
context.Context |
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
package main | |
import ( | |
"context" | |
) | |
func Example_cancellationOrder() { | |
parentCtx, cancelParentCtx := context.WithCancel(context.Background()) | |
//_, cancelChildCtx = context.WithCancel(parentCtx) | |
_, _ = context.WithCancel(parentCtx) |
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
package main | |
import ( | |
"context" | |
"fmt" | |
"time" | |
) | |
func Example_fnDoesntRespectContext() { | |
fn := func(ctx context.Context) { |
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
package main | |
import ( | |
"context" | |
"fmt" | |
) | |
func Example_childCancelsParent() { | |
parentCtx, cancelParentCtx := context.WithCancel(context.Background()) | |
interimValCtx := context.WithValue(parentCtx, "foo", "bar") |
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
package main | |
import ( | |
"context" | |
"fmt" | |
) | |
func Example_parentCancelsChildren() { | |
parentCtx, cancelParentCtx := context.WithCancel(context.Background()) | |
interimValCtx := context.WithValue(parentCtx, "foo", "bar") |
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
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
func Example_multipleReasonsForCancellation() { | |
ctx1, cancel1 := context.WithCancel(context.Background()) | |
ctx2, cancel2 := context.WithTimeout(ctx1, 100*time.Millisecond) | |
ctx, cancel3 := context.WithDeadline(ctx2, time.Now().Add(70*time.Millisecond)) |
NewerOlder