Решение на Concurrent Retry Executor от Андон Мицов

Обратно към всички решения

Към профила на Андон Мицов

Резултати

  • 9 точки от тестове
  • 0 бонус точки
  • 9 точки общо
  • 7 успешни тест(а)
  • 1 неуспешни тест(а)

Код

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
}

Лог от изпълнението

PASS
ok  	_/tmp/d20151110-19113-wxas8l	0.003s
PASS
ok  	_/tmp/d20151110-19113-wxas8l	0.003s
PASS
ok  	_/tmp/d20151110-19113-wxas8l	0.003s
PASS
ok  	_/tmp/d20151110-19113-wxas8l	0.003s
PASS
ok  	_/tmp/d20151110-19113-wxas8l	0.003s
PASS
ok  	_/tmp/d20151110-19113-wxas8l	0.703s
PASS
ok  	_/tmp/d20151110-19113-wxas8l	0.004s
--- FAIL: TestWithManyLogs (0.80s)
	solution_test.go:27: Test exceeded allowed time of 800 milliseconds
FAIL
exit status 1
FAIL	_/tmp/d20151110-19113-wxas8l	0.804s

История (1 версия и 0 коментара)

Андон обнови решението на 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
+}