Станимир обнови решението на 09.11.2015 18:32 (преди над 2 години)
+package main
+
+import "time"
+import "fmt"
+import "sync"
+
+var WaitForIt sync.WaitGroup
+
+//Maybe i will use this in the next version and not the hacky time.Sleep :D
+
+var Lock sync.Mutex
+
+func SendData(buff chan string, result chan string, logNum int) {
+ Lock.Lock()
+ for message := range buff {
+ result <- fmt.Sprintf("%d\t%s", logNum, message)
+ }
+ Lock.Unlock()
+}
+
+func ExceptData(log chan string, result chan string, logNum int) {
+ buff := make(chan string, 100)
+ go SendData(buff, result, logNum)
+ for str := range log {
+ buff <- str
+ }
+ close(buff)
+}
+
+func ChainReaction(logs chan chan string, result chan string) {
+ var logNum int = 0
+ for log := range logs {
+ logNum++
+ go ExceptData(log, result, logNum)
+ time.Sleep(1000 * time.Nanosecond)
+ }
+}
+
+func OrderedLogDrainer(logs chan chan string) chan string {
+ result := make(chan string)
+ WaitForIt.Add(2)
+ go ChainReaction(logs, result)
+ go func() {
+ time.Sleep(1500 * time.Millisecond)
+ close(result)
+ }()
+ return result
+}