github.com/maikovskiys/l1tasks@v0.0.0-20230927052451-6436d7687dc9/develop/dev25/main.go (about) 1 package main 2 3 import ( 4 "context" 5 "fmt" 6 "time" 7 ) 8 9 /* 10 Реализовать собственную функцию sleep. 11 */ 12 const duration = time.Second * 5 13 14 func main() { 15 16 fmt.Println("start") 17 sleep(duration) 18 fmt.Println("finish") 19 20 } 21 func sleep(d time.Duration) { 22 time := time.After(d) 23 ctx, cancel := context.WithDeadline(context.Background(), <-time) 24 25 for { 26 select { 27 case <-ctx.Done(): 28 cancel() 29 return 30 } 31 } 32 }