Решение на Concurrent Retry Executor от Станислав Траилов

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

Към профила на Станислав Траилов

Резултати

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

Код

package main
import (
"sync"
)
func OrderedLogDrainer(logs chan (chan string)) chan string {
result := make(chan string, 100)
var group sync.WaitGroup
go func() {
for ch := range logs {
group.Add(1)
go func() {
select {
case x := <-ch:
result <- x
default:
group.Done()
return
}
}()
group.Wait()
}
}()
return result
}

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

--- FAIL: TestWithOneMessage (0.50s)
	solution_test.go:27: Test exceeded allowed time of 500 milliseconds
FAIL
exit status 1
FAIL	_/tmp/d20151110-19113-4qrovf	0.504s
--- FAIL: TestWithExample1 (0.50s)
	solution_test.go:27: Test exceeded allowed time of 500 milliseconds
FAIL
exit status 1
FAIL	_/tmp/d20151110-19113-4qrovf	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-4qrovf	0.503s
--- FAIL: TestWithNoLogs (0.50s)
	solution_test.go:27: Test exceeded allowed time of 500 milliseconds
FAIL
exit status 1
FAIL	_/tmp/d20151110-19113-4qrovf	0.503s
--- FAIL: TestWithTwoEmptyLogs (0.50s)
	solution_test.go:27: Test exceeded allowed time of 500 milliseconds
FAIL
exit status 1
FAIL	_/tmp/d20151110-19113-4qrovf	0.503s
--- 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-4qrovf	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-4qrovf	0.504s
--- FAIL: TestWithManyLogs (0.80s)
	solution_test.go:27: Test exceeded allowed time of 800 milliseconds
FAIL
exit status 1
FAIL	_/tmp/d20151110-19113-4qrovf	0.803s

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

Станислав обнови решението на 09.11.2015 13:49 (преди над 2 години)

+package main
+
+func ReadChanChan(logs chan (chan string), res chan string) {
+ for ch := range logs {
+ go ReadChan(ch, res)
+ }
+}
+
+func ReadChan(msg chan string, r chan string) {
+ for ch := range msg {
+ r <- "\t" + ch
+ }
+}
+
+func OrderedLogDrainer(logs chan (chan string)) chan string {
+ result := make(chan string, 100)
+ go ReadChanChan(logs, result)
+ return result
+}

Станислав обнови решението на 10.11.2015 13:25 (преди над 2 години)

package main
-func ReadChanChan(logs chan (chan string), res chan string) {
- for ch := range logs {
- go ReadChan(ch, res)
- }
-}
+import (
+ "sync"
+)
-func ReadChan(msg chan string, r chan string) {
- for ch := range msg {
- r <- "\t" + ch
- }
-}
-
func OrderedLogDrainer(logs chan (chan string)) chan string {
- result := make(chan string, 100)
- go ReadChanChan(logs, result)
+ result := make(chan string, 100)
+ var group sync.WaitGroup
+ go func() {
+ for ch := range logs {
+ group.Add(1)
+ go func() {
+ select {
+ case x := <-ch:
+ result <- x
+ default:
+ group.Done()
+ return
+ }
+ }()
+ group.Wait()
+ }
+ }()
return result
}