~ecs/hq

73e27a6aaa620d8b96286d6ac0ccb6a27f195a50 — Eyal Sawady 2 months ago c37556d
Further deadlock fixes
1 files changed, 19 insertions(+), 12 deletions(-)

M main.go
M main.go => main.go +19 -12
@@ 66,6 66,8 @@ func Exec(e Expr, ins []<-chan Datum, out chan Datum) error {
			errs <- Exec(e.Pipe.Second, []<-chan Datum{mid}, out)
		}()
		if err := <-errs; err != nil {
			for range mid {
			}
			<-errs
			return err
		}


@@ 116,11 118,13 @@ func Exec(e Expr, ins []<-chan Datum, out chan Datum) error {
		return <-errs
	}
	if len(e.Cmd) == 0 {
		close(out)
		return errors.New("no filter")
	}
	if filter, ok := Filters[e.Cmd[0]]; ok {
		return filter.Execute(e.Cmd, ins, out)
	}
	close(out)
	return errors.New(e.Cmd[0] + ": not found")
}



@@ 146,26 150,29 @@ func main() {

	in := make(chan Datum)
	out := make(chan Datum)
	errs := make(chan error)

	go func() {
		err = Exec(Exp, []<-chan Datum{in}, out)
		if err != nil {
			fmt.Fprintln(os.Stderr, "exec:", err)
			os.Exit(1)
		}
		errs <- Exec(Exp, []<-chan Datum{in}, out)
	}()
	go func() {
		in <- Datum{HTML: root}
		close(in)
	}()

	for d := range out {
		if d.HTML != nil {
			html.Render(os.Stdout, d.HTML)
			fmt.Println("")
		}
		if d.Text != nil {
			fmt.Println(*d.Text)
	go func() {
		for d := range out {
			if d.HTML != nil {
				html.Render(os.Stdout, d.HTML)
				fmt.Println("")
			}
			if d.Text != nil {
				fmt.Println(*d.Text)
			}
		}
	}()
	if err := <-errs; err != nil {
		fmt.Fprintln(os.Stderr, "exec:", err)
		os.Exit(1)
	}
}