Skip to content

Instantly share code, notes, and snippets.

@aligoren
Created May 29, 2022 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aligoren/7a7bb9c32fe872e953d6bdda88a8b7f4 to your computer and use it in GitHub Desktop.
Save aligoren/7a7bb9c32fe872e953d6bdda88a8b7f4 to your computer and use it in GitHub Desktop.
package main
import (
"context"
"errors"
"fmt"
"time"
)
func AmirimOlayYerine(ctx context.Context) error {
time.Sleep(1200 * time.Millisecond)
return errors.New("Amirimin aracı kaza yaptı")
}
func DinlemeYapiliyor(ctx context.Context) {
fmt.Println("Çok ağır bir yük geliyor ama hadi hayırlısı...")
select {
case <-time.After(2 * time.Second):
fmt.Println("Oh be sonunda bunu tamamladık ya")
case <-ctx.Done():
fmt.Println("Lan noluyor? Bu işlem bir anda durduruldu. Anlayamadım")
}
}
func main() {
ctx := context.Background()
ctx, cancel := context.WithDeadline(ctx, time.Date(2022, time.May, 29, 10, 56, 0, 0, time.UTC))
defer cancel()
go func() {
AmirimOlayYerine(ctx)
}()
DinlemeYapiliyor(ctx)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment