Андон обнови решението на 10.11.2015 12:53 (преди над 2 години)
+package main
+
+import "fmt"
+
+func drainer(log <-chan string, output chan<- string) {
+
+ for msg := range log {
+ output <- msg
+ }
+
+ close(output)
+}
+
+//function for writing log messages to the console output
+func logWriter(chanMessages chan (chan string), out chan string) {
+ //shity variable name
+ var index int = 1
+ for channel := range chanMessages{
+
+
+ for msg := range channel{
+ out <- fmt.Sprintf("%d\t%s",index,msg)
+ }
+ index++
+ }
+
+ close(out)
+}
+
+func OrderedLogDrainer(logsChannel chan (chan string)) (out chan string) {
+ out = make(chan string)
+
+ go func(logs chan (chan string)) {
+ var messagesChannel chan (chan string) = make(chan (chan string), 100)
+ go logWriter(messagesChannel, out)
+
+ for log := range logs {
+ channel := make(chan string,100)
+ messagesChannel <- channel
+ go drainer(log, channel)
+ }
+
+ close(messagesChannel)
+
+ }(logsChannel)
+
+ return
+}