summaryrefslogtreecommitdiff
path: root/src/eventbox.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2015-01-04 05:00:28 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2015-01-04 05:00:28 +0900
commit0dd024a09fc4dd37a596a07e7ff0043537895909 (patch)
tree02f6bc4a614ed3dfe085c9d6c754385a88d58881 /src/eventbox.go
parent0a6cb62169ebe1abb63aa5c70868df7c40441b1c (diff)
downloadfzf-0dd024a09fc4dd37a596a07e7ff0043537895909.tar.gz
Remove unnecessary delay on non/defered interactive mode
Diffstat (limited to 'src/eventbox.go')
-rw-r--r--src/eventbox.go26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/eventbox.go b/src/eventbox.go
index 6685e7c8..95126cca 100644
--- a/src/eventbox.go
+++ b/src/eventbox.go
@@ -9,10 +9,14 @@ type Events map[EventType]interface{}
type EventBox struct {
events Events
cond *sync.Cond
+ ignore map[EventType]bool
}
func NewEventBox() *EventBox {
- return &EventBox{make(Events), sync.NewCond(&sync.Mutex{})}
+ return &EventBox{
+ events: make(Events),
+ cond: sync.NewCond(&sync.Mutex{}),
+ ignore: make(map[EventType]bool)}
}
func (b *EventBox) Wait(callback func(*Events)) {
@@ -30,7 +34,9 @@ func (b *EventBox) Set(event EventType, value interface{}) {
b.cond.L.Lock()
defer b.cond.L.Unlock()
b.events[event] = value
- b.cond.Broadcast()
+ if _, found := b.ignore[event]; !found {
+ b.cond.Broadcast()
+ }
}
// Unsynchronized; should be called within Wait routine
@@ -46,3 +52,19 @@ func (b *EventBox) Peak(event EventType) bool {
_, ok := b.events[event]
return ok
}
+
+func (b *EventBox) Watch(events ...EventType) {
+ b.cond.L.Lock()
+ defer b.cond.L.Unlock()
+ for _, event := range events {
+ delete(b.ignore, event)
+ }
+}
+
+func (b *EventBox) Unwatch(events ...EventType) {
+ b.cond.L.Lock()
+ defer b.cond.L.Unlock()
+ for _, event := range events {
+ b.ignore[event] = true
+ }
+}