@@ -6,7 +6,10 @@ import { CompasSclValidatorService, SVS_NAMESPACE } from "../compas-services/Com
6
6
import { createLogEvent } from "../compas-services/foundation.js" ;
7
7
import { dispatchEventOnOpenScd , getTypeFromDocName } from "../compas/foundation.js" ;
8
8
9
- export default class ValidateTemplates extends LitElement {
9
+ // Boolean to prevent running the validation multiple times at the same time.
10
+ let compasValidationSchemaRunning = false ;
11
+
12
+ export default class CompasValidateSchema extends LitElement {
10
13
@property ( { attribute : false } )
11
14
doc ! : XMLDocument ;
12
15
@@ -18,21 +21,31 @@ export default class ValidateTemplates extends LitElement {
18
21
19
22
async validate ( manual : boolean ) : Promise < void > {
20
23
// We don't want to externally validate every time a save is done. So only start the validation when manually triggered.
21
- if ( ! manual ) {
24
+ // And also if one is already running we don't want to start another one, wait until it's finished.
25
+ if ( ! manual || compasValidationSchemaRunning ) {
22
26
return ;
23
27
}
24
28
29
+ // Block running another validation until this one is finished.
30
+ compasValidationSchemaRunning = true ;
31
+
25
32
const docType = getTypeFromDocName ( this . docName ) ;
26
33
const service = CompasSclValidatorService ( ) ;
27
34
if ( service . useWebsocket ( ) ) {
28
- service . validateSCLUsingWebsockets ( docType , this . doc , ( doc ) => {
29
- this . processValidationResponse ( doc ) ;
30
- } ) ;
35
+ service . validateSCLUsingWebsockets ( docType , this . doc ,
36
+ ( doc ) => {
37
+ this . processValidationResponse ( doc ) ;
38
+ } ,
39
+ ( ) => {
40
+ compasValidationSchemaRunning = false ;
41
+ } ) ;
31
42
} else {
32
43
const response = await service . validateSCLUsingRest ( docType , this . doc )
33
44
. catch ( createLogEvent ) ;
34
45
if ( response instanceof Document ) {
35
46
this . processValidationResponse ( response ) ;
47
+ } else {
48
+ compasValidationSchemaRunning = false ;
36
49
}
37
50
}
38
51
}
@@ -51,5 +64,7 @@ export default class ValidateTemplates extends LitElement {
51
64
) ;
52
65
} )
53
66
}
67
+
68
+ compasValidationSchemaRunning = false ;
54
69
}
55
70
}
0 commit comments