File tree Expand file tree Collapse file tree 1 file changed +20
-4
lines changed
Expand file tree Collapse file tree 1 file changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -9,13 +9,29 @@ module FastWordsCr
99
1010 def self.main (outpath = " words" )
1111 with_sorting = true
12+ concurrent = true
13+
1214 prepare_folder(outpath, " *.txt" )
15+
16+ file_count = 0
17+
18+ processed_files = Channel (Bool ).new
1319 Dir .glob(" ../data/pl/**/*.yml" ).each do |path |
14- # spawn do
20+ if concurrent
21+ spawn do
22+ worker(path, outpath, with_sorting)
23+ processed_files.send true
24+ end
25+ file_count += 1
26+ else
1527 worker(path, outpath, with_sorting)
16- # end
28+ end
29+ end
30+ if concurrent
31+ file_count.times do
32+ processed_files.receive
33+ end
1734 end
18- # Fiber.yield
1935 end
2036
2137 def self.worker (path, outpath, with_sorting)
@@ -24,7 +40,7 @@ module FastWordsCr
2440 words = text.split(/[^\p {L}] +/ ).to_set
2541
2642 if with_sorting
27- words = words.to_a.sort {|x , y | self .word_cmp(x, y)}
43+ words = words.to_a.sort { |x , y | self .word_cmp(x, y) }
2844 end
2945
3046 meta = File .open(path) { |file | YAML .parse(file) }
You can’t perform that action at this time.
0 commit comments