feat: implement context handling with timeout and goroutine management

This commit is contained in:
2025-10-13 20:09:51 +03:00
parent 328b4cc66e
commit e911403bba
2 changed files with 23 additions and 31 deletions

View File

@@ -1,38 +1,26 @@
package main
import (
"fmt"
"sipro-mps/internal/ym/products"
"context"
"sync"
"time"
)
// package main
//
// import (
//
// "context"
// "fmt"
// "sipro-mps/internal/wb/products/mapping/generated"
// "strings"
//
// pb "sipro-mps/api/generated/v1/wb/products"
// "sipro-mps/pkg/api/wb/client"
//
// "github.com/deliveryhero/pipeline/v2"
//
// )
//
// func main() {
//
// input := "1,2,3,4,5"
//
// for out := range pipeline.Process(context.Background(), apply, pipeline.Emit(input)) {
// for j := range out {
// fmt.Printf("process: %s\n", out[j])
// }
// }
// }
func main() {
rs := products.GetCategoriesError("{\"status\":\"ERROR\",\"errors\":[{\"code\":\"BAD_REQUEST\",\"message\":\"Following categories are not leaf categories: 91735\"}]}")
fmt.Println(rs)
ctx, cacnel := context.WithTimeout(context.Background(), time.Second*5)
defer cacnel()
wg := sync.WaitGroup{}
go func() {
defer func() {
wg.Done()
println("goroutine exit")
}()
select {
case <-ctx.Done():
println("context done")
return
}
}()
wg.Add(1)
wg.Wait()
}