Download pkg/tools/stack.go from xiaozhian/kpl: direct link, hf CLI and curl.
- Browser
- Download file 443 Bytes
-
https://huggingface.co/spaces/xiaozhian/kpl/resolve/main/pkg/tools/stack.go
- Command line
-
hf download hf://spaces/xiaozhian/kpl/pkg/tools/stack.go
-
curl -L -o stack.go https://huggingface.co/spaces/xiaozhian/kpl/resolve/main/pkg/tools/stack.go
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 | |
| } | |