Spaces:
Running
Running
package tools | |
import ( | |
"context" | |
"sync" | |
) | |
type Stack struct { | |
sync.Mutex | |
items []func(context.Context) | |
} | |
func (s *Stack) Pop() func(context.Context) { | |
s.Lock() | |
defer s.Unlock() | |
item := s.items[len(s.items)-1] | |
s.items = s.items[:len(s.items)-1] | |
return item | |
} | |
func (s *Stack) Push(item func(context.Context)) { | |
s.Lock() | |
defer s.Unlock() | |
s.items = append(s.items, item) | |
} | |
func (s *Stack) Next() bool { | |
return len(s.items) > 0 | |
} | |