@@ -501,6 +501,11 @@ export abstract class ExtHostTaskBase implements ExtHostTaskShape, IExtHostTask
501
501
}
502
502
503
503
public async $OnDidEndTask ( execution : tasks . ITaskExecutionDTO ) : Promise < void > {
504
+ if ( ! this . _taskExecutionPromises . has ( execution . id ) ) {
505
+ // Event already fired by the main thread
506
+ // See https://github.com/microsoft/vscode/commit/aaf73920aeae171096d205efb2c58804a32b6846
507
+ return ;
508
+ }
504
509
const _execution = await this . getTaskExecution ( execution ) ;
505
510
this . _taskExecutionPromises . delete ( execution . id ) ;
506
511
this . _taskExecutions . delete ( execution . id ) ;
@@ -633,29 +638,22 @@ export abstract class ExtHostTaskBase implements ExtHostTaskShape, IExtHostTask
633
638
if ( result ) {
634
639
return result ;
635
640
}
636
- const createdResult : Promise < TaskExecutionImpl > = new Promise ( ( resolve , reject ) => {
637
- function resolvePromiseWithCreatedTask ( that : ExtHostTaskBase , execution : tasks . ITaskExecutionDTO , taskToCreate : vscode . Task | types . Task | undefined ) {
638
- if ( ! taskToCreate ) {
639
- reject ( 'Unexpected: Task does not exist.' ) ;
640
- } else {
641
- resolve ( new TaskExecutionImpl ( that , execution . id , taskToCreate ) ) ;
642
- }
643
- }
644
641
645
- if ( task ) {
646
- resolvePromiseWithCreatedTask ( this , execution , task ) ;
647
- } else {
648
- TaskDTO . to ( execution . task , this . _workspaceProvider , this . _providedCustomExecutions2 )
649
- . then ( task => resolvePromiseWithCreatedTask ( this , execution , task ) ) ;
650
- }
651
- } ) ;
652
-
653
- this . _taskExecutionPromises . set ( execution . id , createdResult ) ;
654
- return createdResult . then ( executionCreatedResult => {
655
- this . _taskExecutions . set ( execution . id , executionCreatedResult ) ;
656
- return executionCreatedResult ;
657
- } , rejected => {
658
- return Promise . reject ( rejected ) ;
642
+ let executionPromise : Promise < TaskExecutionImpl > ;
643
+ if ( ! task ) {
644
+ executionPromise = TaskDTO . to ( execution . task , this . _workspaceProvider , this . _providedCustomExecutions2 ) . then ( t => {
645
+ if ( ! t ) {
646
+ throw new ErrorNoTelemetry ( 'Unexpected: Task does not exist.' ) ;
647
+ }
648
+ return new TaskExecutionImpl ( this , execution . id , t ) ;
649
+ } ) ;
650
+ } else {
651
+ executionPromise = Promise . resolve ( new TaskExecutionImpl ( this , execution . id , task ) ) ;
652
+ }
653
+ this . _taskExecutionPromises . set ( execution . id , executionPromise ) ;
654
+ return executionPromise . then ( taskExecution => {
655
+ this . _taskExecutions . set ( execution . id , taskExecution ) ;
656
+ return taskExecution ;
659
657
} ) ;
660
658
}
661
659
0 commit comments