Spaces:
Running
Running
File size: 443 Bytes
a4468f1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
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
}
|