basket.go 464 B

1234567891011121314151617181920212223242526
  1. package workers
  2. import (
  3. "context"
  4. "time"
  5. "golang-fave/engine/basket"
  6. "github.com/vladimirok5959/golang-worker/worker"
  7. )
  8. func BasketCleaner(sb *basket.Basket) *worker.Worker {
  9. return worker.New(func(ctx context.Context, w *worker.Worker, o *[]worker.Iface) {
  10. select {
  11. case <-ctx.Done():
  12. return
  13. case <-time.After(1 * time.Second):
  14. if sb, ok := (*o)[0].(*basket.Basket); ok {
  15. sb.Cleanup()
  16. }
  17. return
  18. }
  19. }, &[]worker.Iface{
  20. sb,
  21. })
  22. }