@@ -107,6 +107,7 @@ export class Actions extends BaseActions<LatexEditorState> {
107
107
private _last_sagetex_hash : string ;
108
108
private _last_syncstring_hash : number | undefined ;
109
109
private is_building : boolean = false ;
110
+ private is_stopping : boolean = false ; // if true, do not continue running any compile jobs
110
111
private ext : string = "tex" ;
111
112
private knitr : boolean = false ; // true, if we deal with a knitr file
112
113
private filename_knitr : string ; // .rnw or .rtex
@@ -725,7 +726,7 @@ export class Actions extends BaseActions<LatexEditorState> {
725
726
// likely "No such process", we just ignore it
726
727
} finally {
727
728
// set this build log to be no longer running
728
- job . status = "completed " ;
729
+ job . status = "killed " ;
729
730
}
730
731
}
731
732
return job ;
@@ -734,17 +735,23 @@ export class Actions extends BaseActions<LatexEditorState> {
734
735
// This stops all known jobs with a status "running" and resets the state.
735
736
async stop_build ( _id ?: string ) {
736
737
const build_logs = this . store . get ( "build_logs" ) ;
737
- if ( build_logs ) {
738
- for ( const [ name , job ] of build_logs ) {
739
- this . set_build_logs ( { [ name ] : await this . kill ( job . toJS ( ) ) } ) ;
738
+ try {
739
+ this . is_stopping = true ;
740
+ if ( build_logs ) {
741
+ for ( const [ name , job ] of build_logs ) {
742
+ // this.kill returns the job with a modified status, it's not the kill exec itself
743
+ this . set_build_logs ( { [ name ] : await this . kill ( job . toJS ( ) ) } ) ;
744
+ }
740
745
}
746
+ } finally {
747
+ this . set_status ( "" ) ;
748
+ this . is_building = false ;
749
+ this . is_stopping = false ;
741
750
}
742
-
743
- this . set_status ( "" ) ;
744
- this . is_building = false ;
745
751
}
746
752
747
753
private async run_build ( time : number , force : boolean ) : Promise < void > {
754
+ if ( this . is_stopping ) return ;
748
755
// reset state of build_logs, since it is a fresh start
749
756
this . setState ( { build_logs : Map ( ) } ) ;
750
757
@@ -807,6 +814,7 @@ export class Actions extends BaseActions<LatexEditorState> {
807
814
}
808
815
809
816
private async run_knitr ( time : number , force : boolean ) : Promise < void > {
817
+ if ( this . is_stopping ) return ;
810
818
let output : BuildLog ;
811
819
const status = ( s ) => this . set_status ( `Running Knitr... ${ s } ` ) ;
812
820
const set_job_info = ( job ) => this . set_build_logs ( { knitr : job } ) ;
@@ -890,6 +898,7 @@ export class Actions extends BaseActions<LatexEditorState> {
890
898
force : boolean ,
891
899
update_pdf : boolean = true ,
892
900
) : Promise < void > {
901
+ if ( this . is_stopping ) return ;
893
902
let output : BuildLog ;
894
903
let build_command : string | string [ ] ;
895
904
const timestamp = this . make_timestamp ( time , force ) ;
@@ -1105,6 +1114,7 @@ export class Actions extends BaseActions<LatexEditorState> {
1105
1114
}
1106
1115
1107
1116
async run_sagetex ( time : number , force : boolean ) : Promise < void > {
1117
+ if ( this . is_stopping ) return ;
1108
1118
const status = ( s ) => this . set_status ( `Running SageTeX... ${ s } ` ) ;
1109
1119
const set_job_info = ( job ) => this . set_build_logs ( { sagetex : job } ) ;
1110
1120
status ( "" ) ;
@@ -1174,6 +1184,7 @@ export class Actions extends BaseActions<LatexEditorState> {
1174
1184
}
1175
1185
1176
1186
async run_pythontex ( time : number , force : boolean ) : Promise < void > {
1187
+ if ( this . is_stopping ) return ;
1177
1188
let output : BuildLog ;
1178
1189
const status = ( s ) => this . set_status ( `Running PythonTeX... ${ s } ` ) ;
1179
1190
const set_job_info = ( job ) => this . set_build_logs ( { pythontex : job } ) ;
0 commit comments