Created
May 29, 2022 19:58
-
-
Save aligoren/7a7bb9c32fe872e953d6bdda88a8b7f4 to your computer and use it in GitHub Desktop.
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
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