diff --git a/respond/collector.go b/respond/collector.go index ae52cf0..d905921 100644 --- a/respond/collector.go +++ b/respond/collector.go @@ -24,7 +24,7 @@ type Collector struct { type OnReceive func(net.UDPAddr, interface{}) //NewCollector creates a Collector struct -func NewCollector(CollectType string, interval time.Duration, msgStruct interface{}, onReceive OnReceive) *Collector { +func NewCollector(CollectType string, initialDelay time.Duration, interval time.Duration, msgStruct interface{}, onReceive OnReceive) *Collector { // Parse address addr, err := net.ResolveUDPAddr("udp", "[::]:0") if err != nil { @@ -52,8 +52,11 @@ func NewCollector(CollectType string, interval time.Duration, msgStruct interfac go collector.parser() // Run senders - go collector.sendOnce() // immediately - go collector.sender() // periodically + go func() { + time.Sleep(initialDelay) + collector.sendOnce() // immediately + collector.sender() // periodically + }() return collector } diff --git a/respond/multi_collector.go b/respond/multi_collector.go index a46d6a4..85c7b09 100644 --- a/respond/multi_collector.go +++ b/respond/multi_collector.go @@ -14,9 +14,9 @@ type MultiCollector struct { func NewMultiCollector(interval time.Duration, onReceive OnReceive) *MultiCollector { return &MultiCollector{ collectors: []*Collector{ - NewCollector("statistics", interval, data.Statistics{}, onReceive), - NewCollector("nodeinfo", interval, data.NodeInfo{}, onReceive), - NewCollector("neighbours", interval, data.Neighbours{}, onReceive), + NewCollector("statistics", 0, interval, data.Statistics{}, onReceive), + NewCollector("nodeinfo", time.Second*3, interval, data.NodeInfo{}, onReceive), + NewCollector("neighbours", time.Second*6, interval, data.Neighbours{}, onReceive), }, } }