Skip to content

Instantly share code, notes, and snippets.

View ostretsov's full-sized avatar
🏠
Working from home

Artem Ostretsov ostretsov

🏠
Working from home
View GitHub Profile
package main
import (
"fmt"
"net/http"
"net/http/httptest"
"time"
)
func Example_limitHandlerExecutionTime() {
package main
import (
"context"
"fmt"
"net"
"net/http"
"net/http/httptest"
)
package main
import (
"errors"
"fmt"
"io"
"net"
"net/http"
"net/http/httptest"
)
package main
import (
"context"
"fmt"
"regexp"
"time"
)
func Example_contextHierarchy() {
package main
import (
"context"
"fmt"
"runtime"
)
type myCtx struct {
context.Context
package main
import (
"context"
)
func Example_cancellationOrder() {
parentCtx, cancelParentCtx := context.WithCancel(context.Background())
//_, cancelChildCtx = context.WithCancel(parentCtx)
_, _ = context.WithCancel(parentCtx)
package main
import (
"context"
"fmt"
"time"
)
func Example_fnDoesntRespectContext() {
fn := func(ctx context.Context) {
package main
import (
"context"
"fmt"
)
func Example_childCancelsParent() {
parentCtx, cancelParentCtx := context.WithCancel(context.Background())
interimValCtx := context.WithValue(parentCtx, "foo", "bar")
package main
import (
"context"
"fmt"
)
func Example_parentCancelsChildren() {
parentCtx, cancelParentCtx := context.WithCancel(context.Background())
interimValCtx := context.WithValue(parentCtx, "foo", "bar")
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))