mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2024-11-15 21:51:23 +08:00
34 lines
466 B
Go
34 lines
466 B
Go
package observable
|
|
|
|
import (
|
|
"sync"
|
|
)
|
|
|
|
type Subscription <-chan interface{}
|
|
|
|
type Subscriber struct {
|
|
buffer chan interface{}
|
|
once sync.Once
|
|
}
|
|
|
|
func (s *Subscriber) Emit(item interface{}) {
|
|
s.buffer <- item
|
|
}
|
|
|
|
func (s *Subscriber) Out() Subscription {
|
|
return s.buffer
|
|
}
|
|
|
|
func (s *Subscriber) Close() {
|
|
s.once.Do(func() {
|
|
close(s.buffer)
|
|
})
|
|
}
|
|
|
|
func newSubscriber() *Subscriber {
|
|
sub := &Subscriber{
|
|
buffer: make(chan interface{}, 200),
|
|
}
|
|
return sub
|
|
}
|