func longRunningTask(ctx context.Context) { select { case <-time.After(time.Minute): fmt.Println("Long running task completed") case <-ctx.Done(): fmt.Println("Long running task canceled") } } func main() { ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() go longRunningTask(ctx) select { case <-time.After(time.Second * 2): fmt.Println("Main function completed") case <-ctx.Done(): fmt.Println("Main function canceled") } }In this example, a long running task is simulated using a time.After function that waits for a minute. However, this task can be aborted early if the context is canceled or times out. The main function waits for two seconds to complete, but it can also be canceled early if the long running task is terminated by the context.