github.com/zignig/go-ipfs@v0.0.0-20141111235910-c9e5fdf55a52/fuse/ipns/repub_unix.go (about) 1 package ipns 2 3 import "time" 4 5 type Republisher struct { 6 TimeoutLong time.Duration 7 TimeoutShort time.Duration 8 Publish chan struct{} 9 node *Node 10 } 11 12 func NewRepublisher(n *Node, tshort, tlong time.Duration) *Republisher { 13 return &Republisher{ 14 TimeoutShort: tshort, 15 TimeoutLong: tlong, 16 Publish: make(chan struct{}), 17 node: n, 18 } 19 } 20 21 func (np *Republisher) Run() { 22 for _ = range np.Publish { 23 quick := time.After(np.TimeoutShort) 24 longer := time.After(np.TimeoutLong) 25 26 wait: 27 select { 28 case <-quick: 29 case <-longer: 30 case <-np.Publish: 31 quick = time.After(np.TimeoutShort) 32 goto wait 33 } 34 35 log.Info("Publishing Changes!") 36 err := np.node.republishRoot() 37 if err != nil { 38 log.Critical("republishRoot error: %s", err) 39 } 40 41 } 42 }