@@ -2,20 +2,22 @@ package cssminify
2
2
3
3
import (
4
4
"bufio"
5
- "fmt"
6
5
"os"
6
+ "sync"
7
7
)
8
8
9
9
type Block struct {
10
10
selector []byte
11
11
pairs []Pair
12
12
}
13
13
14
- func Blocks (cb chan Block , file string ) {
14
+ func Blocks (cb chan Block , file string , wg sync. WaitGroup ) {
15
15
cf := make (chan byte )
16
16
17
- go readFile (cf , file )
18
- go parse (cf , cb )
17
+ wg .Add (1 )
18
+ go readFile (cf , file , wg )
19
+ wg .Add (1 )
20
+ go parse (cf , cb , wg )
19
21
}
20
22
21
23
func stripLetter (content []byte ) (byte , []byte ) {
@@ -29,7 +31,7 @@ func stripLetter(content []byte) (byte, []byte) {
29
31
return letter , content
30
32
}
31
33
32
- func readFile (cf chan byte , root string ) {
34
+ func readFile (cf chan byte , root string , wg sync. WaitGroup ) {
33
35
file , err := os .Open (root )
34
36
if err != nil {
35
37
panic (err )
@@ -38,15 +40,17 @@ func readFile(cf chan byte, root string) {
38
40
39
41
reader := bufio .NewReader (file )
40
42
for b , err := reader .ReadByte (); err != nil ; b , err = reader .ReadByte () {
41
- fmt .Printf ("%c\n " , b )
42
43
cf <- b
43
44
}
45
+ defer wg .Done ()
44
46
}
45
47
46
- func parse (cf chan byte , cb chan Block ) {
48
+ func parse (cf chan byte , cb chan Block , wg sync. WaitGroup ) {
47
49
var letter byte
48
50
state := new (State )
49
51
for letter = <- cf ; letter != 0 ; letter = <- cf {
50
- state .parse (cf , cb )
52
+ wg .Add (1 )
53
+ state .parse (cf , cb , wg )
51
54
}
55
+ defer wg .Done ()
52
56
}
0 commit comments