mar-755-KK / pkg /tools /stack.go
aurorax-neo's picture
init
a4468f1
raw
history blame
443 Bytes
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
}