Skip to content

Commit

Permalink
minor modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
shijuvar committed Feb 28, 2024
1 parent 8c0b1f5 commit 46354e0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions examples/concurrencyx/ctx-cancel/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ func generateValues(ctx context.Context, counter chan int) {

func main() {
causeError := errors.New("goroutine is leaking")
ctx, cancel := context.WithCancelCause(context.Background())
//ctx, cancel := context.WithCancelCause(context.Background())
ctx, cancel := context.WithTimeoutCause(context.Background(), 3*time.Second, causeError)
defer cancel()
counter := make(chan int)
// calling goroutine with ctx-cancel value
go generateValues(ctx, counter)
for n := range counter {
if n == 10 {
cancel(causeError)
}
//if n == 5 {
// cancel(causeError)
//}
fmt.Println(n)
}
fmt.Println("done")
Expand Down
2 changes: 1 addition & 1 deletion examples/context/afterfunc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func main() {
go doSomething(ctx, wg)
cancel()
// Calling the returned stop function stops the association of ctx with f
stop()
//stop()
if !stop() {
fmt.Println("stop func has been started in its own goroutine; or stop func was already stopped.")
}
Expand Down

0 comments on commit 46354e0

Please sign in to comment.