OLD | NEW |
1 // The watcher package provides an interface for observing changes | 1 // The watcher package provides an interface for observing changes |
2 // to arbitrary MongoDB documents that are maintained via the | 2 // to arbitrary MongoDB documents that are maintained via the |
3 // mgo/txn transaction package. | 3 // mgo/txn transaction package. |
4 package watcher | 4 package watcher |
5 | 5 |
6 import ( | 6 import ( |
7 "fmt" | 7 "fmt" |
8 "labix.org/v2/mgo" | 8 "labix.org/v2/mgo" |
9 "labix.org/v2/mgo/bson" | 9 "labix.org/v2/mgo/bson" |
10 "launchpad.net/juju-core/log" | 10 "launchpad.net/juju-core/log" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 }() | 90 }() |
91 return w | 91 return w |
92 } | 92 } |
93 | 93 |
94 // Stop stops all the watcher activities. | 94 // Stop stops all the watcher activities. |
95 func (w *Watcher) Stop() error { | 95 func (w *Watcher) Stop() error { |
96 w.tomb.Kill(nil) | 96 w.tomb.Kill(nil) |
97 return w.tomb.Wait() | 97 return w.tomb.Wait() |
98 } | 98 } |
99 | 99 |
100 // Dying returns a channel that is closed when the watcher is stopping | 100 // Dead returns a channel that is closed when the watcher has stopped. |
101 // due to an error or because Stop was called explicitly. | 101 func (w *Watcher) Dead() <-chan struct{} { |
102 func (w *Watcher) Dying() <-chan struct{} { | 102 return w.tomb.Dead() |
103 return w.tomb.Dying() | |
104 } | 103 } |
105 | 104 |
106 // Err returns the error with which the watcher stopped. | 105 // Err returns the error with which the watcher stopped. |
107 // It returns nil if the watcher stopped cleanly, tomb.ErrStillAlive | 106 // It returns nil if the watcher stopped cleanly, tomb.ErrStillAlive |
108 // if the watcher is still running properly, or the respective error | 107 // if the watcher is still running properly, or the respective error |
109 // if the watcher is terminating or has terminated with an error. | 108 // if the watcher is terminating or has terminated with an error. |
110 func (w *Watcher) Err() error { | 109 func (w *Watcher) Err() error { |
111 return w.tomb.Err() | 110 return w.tomb.Err() |
112 } | 111 } |
113 | 112 |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 } | 390 } |
392 } | 391 } |
393 } | 392 } |
394 } | 393 } |
395 } | 394 } |
396 if iter.Err() != nil { | 395 if iter.Err() != nil { |
397 return fmt.Errorf("watcher iteration error: %v", iter.Err()) | 396 return fmt.Errorf("watcher iteration error: %v", iter.Err()) |
398 } | 397 } |
399 return nil | 398 return nil |
400 } | 399 } |
OLD | NEW |