Revert "thread: Close channels"

This reverts commit 00e78c1eae.

Reason: (*Thread).Loop can be called multiple times on iOS.

Fixes #1121
This commit is contained in:
Hajime Hoshi 2020-03-29 16:25:15 +09:00
parent a9c74e48e1
commit 41d07706ae

View File

@ -22,7 +22,6 @@ import (
type Thread struct {
funcs chan func() error
results chan error
closed chan struct{}
}
// New creates a new thread.
@ -32,7 +31,6 @@ func New() *Thread {
return &Thread{
funcs: make(chan func() error),
results: make(chan error),
closed: make(chan struct{}),
}
}
@ -40,9 +38,6 @@ func New() *Thread {
//
// Loop must be called on the thread.
func (t *Thread) Loop(context context.Context) {
defer close(t.closed)
defer close(t.results)
defer close(t.funcs)
loop:
for {
select {
@ -60,10 +55,6 @@ loop:
//
// Call panics when Loop already ends.
func (t *Thread) Call(f func() error) error {
select {
case t.funcs <- f:
return <-t.results
case <-t.closed:
panic("thread: this thread is already terminated")
}
t.funcs <- f
return <-t.results
}