Решение на Concurrent Retry Executor от Андрея Костов

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

Към профила на Андрея Костов

Резултати

  • 3 точки от тестове
  • 0 бонус точки
  • 3 точки общо
  • 2 успешни тест(а)
  • 6 неуспешни тест(а)

Код

package main
import "fmt"
func OrderedLogDrainer(logs chan (chan string)) chan string {
combined := make(chan string, cap(logs)*100)
go func(combined chan string, logs chan (chan string)) {
i := 0
for logChan := range logs {
i++
extractFromLog(&i, &logChan, &combined)
}
close(combined)
}(combined, logs)
return combined
}
func extractFromLog(i *int, log, result *chan string) {
for val := range *log {
*result <- fmt.Sprintf("%v\t%v", *i, val)
}
}

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

PASS
ok  	_/tmp/d20151110-19113-m4u6b	0.003s
--- FAIL: TestWithExample1 (0.50s)
	solution_test.go:27: Test exceeded allowed time of 500 milliseconds
FAIL
exit status 1
FAIL	_/tmp/d20151110-19113-m4u6b	0.503s
--- FAIL: TestWithExample2 (0.50s)
	solution_test.go:27: Test exceeded allowed time of 500 milliseconds
FAIL
exit status 1
FAIL	_/tmp/d20151110-19113-m4u6b	0.503s
PASS
ok  	_/tmp/d20151110-19113-m4u6b	0.003s
--- FAIL: TestWithTwoEmptyLogs (0.50s)
	solution_test.go:27: Test exceeded allowed time of 500 milliseconds
FAIL
exit status 1
FAIL	_/tmp/d20151110-19113-m4u6b	0.504s
--- FAIL: TestWithDelays (0.90s)
	solution_test.go:27: Test exceeded allowed time of 400 milliseconds
	solution_test.go:27: Test exceeded allowed time of 900 milliseconds
FAIL
exit status 1
FAIL	_/tmp/d20151110-19113-m4u6b	0.903s
--- FAIL: TestTheLimits (0.50s)
	solution_test.go:27: Test exceeded allowed time of 500 milliseconds
FAIL
exit status 1
FAIL	_/tmp/d20151110-19113-m4u6b	0.503s
--- FAIL: TestWithManyLogs (0.80s)
	solution_test.go:27: Test exceeded allowed time of 800 milliseconds
FAIL
exit status 1
FAIL	_/tmp/d20151110-19113-m4u6b	0.804s

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

Андрея обнови решението на 10.11.2015 11:02 (преди над 2 години)

+package main
+
+import "fmt"
+
+func OrderedLogDrainer(logs chan (chan string)) chan string {
+ combined := make(chan string, cap(logs)*100)
+
+ go func(combined chan string, logs chan (chan string)) {
+ i := 0
+ for logChan := range logs {
+ i++
+ extractFromLog(&i, &logChan, &combined)
+ }
+ close(combined)
+ }(combined, logs)
+
+ return combined
+}
+
+func extractFromLog(i *int, log, result *chan string) {
+ for val := range *log {
+ *result <- fmt.Sprintf("%v\t%v", *i, val)
+ }
+}