Skip to content

Commit 1837a8c

Browse files
committed
Cli: use Chanhowdoi
1 parent 8ab720d commit 1837a8c

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

main.go

+24-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"log"
66
"os"
7+
"strconv"
78

89
howdoi "github.com/chinanf-boy/howdoi/pkg"
910
"github.com/logrusorgru/aurora"
@@ -32,15 +33,32 @@ func main() {
3233
log.Fatalln(err)
3334
}
3435

36+
cliChan := make(chan string)
37+
done := make(chan int)
3538
// pass howdoi.Cli
36-
result, err := howdoi.Howdoi(res)
39+
go func() {
40+
n := 0
41+
for i := 0; i < 1; i++ {
42+
s := <-cliChan
43+
n, _ = strconv.Atoi(s)
44+
// fmt.Printf("form ChanHowdoi %s\n", s)
45+
}
46+
47+
for i := 0; i < n; i++ {
48+
fmt.Println()
49+
fmt.Println(<-cliChan)
50+
51+
}
52+
close(cliChan)
53+
done <- 0
54+
55+
}()
56+
57+
err = howdoi.ChanHowdoi(res, cliChan)
3758

3859
if err != nil {
3960
log.Fatalln(err)
4061
}
41-
42-
for _, v := range result {
43-
fmt.Println()
44-
fmt.Println(v)
45-
}
62+
<-done
63+
close(done)
4664
}

0 commit comments

Comments
 (0)