@@ -19,6 +19,7 @@ use futures::executor::ThreadPool;
1919use futures:: future:: join_all;
2020use futures:: stream:: StreamExt ;
2121use futures:: task:: SpawnExt ;
22+ use std:: sync:: { Arc , Mutex } ;
2223
2324/// main() helps to generate the submission template .rs
2425fn main ( ) {
@@ -63,18 +64,9 @@ fn main() {
6364 let pool = ThreadPool :: new ( ) . unwrap ( ) ;
6465 let mut tasks = vec ! [ ] ;
6566 let problems = fetcher:: get_problems ( ) . unwrap ( ) ;
66- let mut mod_file_addon = vec ! [ ] ;
67+ let mut mod_file_addon = Arc :: new ( Mutex :: new ( vec ! [ ] ) ) ;
6768 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 ( ) ;
7870 tasks. push (
7971 pool. spawn_with_handle ( async move {
8072 let problem = fetcher:: get_problem_async ( problem_stat) . await ;
@@ -90,6 +82,14 @@ fn main() {
9082 println ! ( "Problem {} has no rust version." , problem. question_id) ;
9183 return ;
9284 }
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 ;
9393 let code = code. unwrap ( ) ;
9494 async { deal_problem ( & problem, & code, false ) } . await
9595 } )
@@ -102,7 +102,7 @@ fn main() {
102102 . append ( true )
103103 . open ( "./src/problem/mod.rs" )
104104 . unwrap ( ) ;
105- writeln ! ( lib_file, "{}" , mod_file_addon. join( "\n " ) ) ;
105+ writeln ! ( lib_file, "{}" , mod_file_addon. lock ( ) . unwrap ( ) . join( "\n " ) ) ;
106106 break ;
107107 } else {
108108 id = id_arg
0 commit comments