Skip to content

Commit 319e6e7

Browse files
committed
Fix possibly undefined cancelSource
Since we are waiting for async start now, it is possible to get callbacks before cancelSource is created.
1 parent 00833db commit 319e6e7

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/device.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ export class Device extends vscode.Disposable {
560560
service: 'sftp-ssh'
561561
});
562562
const items = new Array<ServiceItem>();
563-
let cancelSource: vscode.CancellationTokenSource;
563+
let cancelSource: vscode.CancellationTokenSource | undefined;
564564
let done = false;
565565

566566
// if a device is added or removed, cancel the quick-pick
@@ -577,21 +577,21 @@ export class Device extends vscode.Disposable {
577577
}
578578
const item = new ServiceItem(service);
579579
items.push(item);
580-
cancelSource.cancel();
580+
cancelSource?.cancel();
581581
}
582582
});
583583
browser.on('removed', (service) => {
584584
const index = items.findIndex(si => si.service === service);
585585
if (index > -1) {
586586
items.splice(index, 1);
587-
cancelSource.cancel();
587+
cancelSource?.cancel();
588588
}
589589
});
590590

591591
// if there is a browser error, cancel the quick-pick and show
592592
// an error message
593593
browser.on('error', err => {
594-
cancelSource.cancel();
594+
cancelSource?.cancel();
595595
browser.destroy();
596596
done = true;
597597
reject(err);

0 commit comments

Comments
 (0)