Don't close ports in Closure.Call.

This fixes #92.
This commit is contained in:
Qi Xiao 2016-02-09 01:17:48 +01:00
parent 227f9a8d2a
commit f3c82a65b0
3 changed files with 4 additions and 1 deletions

View File

@ -102,6 +102,7 @@ func (cp *compiler) pipeline(n *parse.Pipeline) Op {
thisError := &errors[i]
go func() {
(*thisError).inner = newEc.PEval(thisOp)
// Logger.Printf("closing ports of %s", newEc.context)
ClosePorts(newEc.ports)
finished <- true
}()
@ -328,6 +329,7 @@ func (cp *compiler) redir(n *parse.Redir) Op {
}
ec.growPorts(dst + 1)
// Logger.Printf("closing old port %d of %s", dst, ec.context)
ec.ports[dst].Close()
srcMust := ec.must(srcOp(ec), "redirection source", pSrc)

View File

@ -89,7 +89,6 @@ func (c *Closure) Call(ec *evalCtx, args []Value) {
// TODO(xiaq): Also change ec.name and ec.text since the closure being
// called can come from another source.
ClosePorts(ec.ports)
c.Op(ec)
}

View File

@ -19,6 +19,7 @@ func (p *Port) Close() {
p.File.Close()
}
if p.CloseChan {
// Logger.Printf("closing channel %v", p.Chan)
close(p.Chan)
}
}
@ -26,6 +27,7 @@ func (p *Port) Close() {
// closePorts closes a list of Ports.
func ClosePorts(ports []*Port) {
for _, port := range ports {
// Logger.Printf("closing port %d", i)
port.Close()
}
}