@@ -19,6 +19,7 @@ use futures::executor::ThreadPool;
19
19
use futures:: future:: join_all;
20
20
use futures:: stream:: StreamExt ;
21
21
use futures:: task:: SpawnExt ;
22
+ use std:: sync:: { Arc , Mutex } ;
22
23
23
24
/// main() helps to generate the submission template .rs
24
25
fn main ( ) {
@@ -63,18 +64,9 @@ fn main() {
63
64
let pool = ThreadPool :: new ( ) . unwrap ( ) ;
64
65
let mut tasks = vec ! [ ] ;
65
66
let problems = fetcher:: get_problems ( ) . unwrap ( ) ;
66
- let mut mod_file_addon = vec ! [ ] ;
67
+ let mut mod_file_addon = Arc :: new ( Mutex :: new ( vec ! [ ] ) ) ;
67
68
for problem_stat in problems. stat_status_pairs {
68
- mod_file_addon. push ( format ! (
69
- "mod p{:04}_{};" ,
70
- problem_stat. stat. frontend_question_id,
71
- problem_stat
72
- . stat
73
- . question_title_slug
74
- . clone( )
75
- . unwrap( )
76
- . replace( "-" , "_" )
77
- ) ) ;
69
+ let mod_file_addon = mod_file_addon. clone ( ) ;
78
70
tasks. push (
79
71
pool. spawn_with_handle ( async move {
80
72
let problem = fetcher:: get_problem_async ( problem_stat) . await ;
@@ -90,6 +82,14 @@ fn main() {
90
82
println ! ( "Problem {} has no rust version." , problem. question_id) ;
91
83
return ;
92
84
}
85
+ async {
86
+ mod_file_addon. lock ( ) . unwrap ( ) . push ( format ! (
87
+ "mod p{:04}_{};" ,
88
+ problem. question_id,
89
+ problem. title_slug. replace( "-" , "_" )
90
+ ) ) ;
91
+ }
92
+ . await ;
93
93
let code = code. unwrap ( ) ;
94
94
async { deal_problem ( & problem, & code, false ) } . await
95
95
} )
@@ -102,7 +102,7 @@ fn main() {
102
102
. append ( true )
103
103
. open ( "./src/problem/mod.rs" )
104
104
. unwrap ( ) ;
105
- writeln ! ( lib_file, "{}" , mod_file_addon. join( "\n " ) ) ;
105
+ writeln ! ( lib_file, "{}" , mod_file_addon. lock ( ) . unwrap ( ) . join( "\n " ) ) ;
106
106
break ;
107
107
} else {
108
108
id = id_arg
0 commit comments