Skip to content

Commit d04c6ef

Browse files
fix initial sync with extension host
1 parent 51fd561 commit d04c6ef

File tree

2 files changed

+15
-19
lines changed
  • packages/app/src/app/overmind/effects/vscode

2 files changed

+15
-19
lines changed

packages/app/src/app/overmind/effects/vscode/extensionHostWorker/common/fs.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export async function initializeBrowserFS({
5555
syncTypes = false,
5656
extraMounts = {},
5757
} = {}) {
58+
let hasInitialSync = false;
5859
return new Promise(resolve => {
5960
const config = { ...BROWSER_FS_CONFIG };
6061
let currentSandboxFs = {};
@@ -92,6 +93,10 @@ export async function initializeBrowserFS({
9293
switch (evt.data.$type) {
9394
case 'sandbox-fs': {
9495
currentSandboxFs = evt.data.$data;
96+
if (!hasInitialSync) {
97+
hasInitialSync = true;
98+
resolve();
99+
}
95100
break;
96101
}
97102
case 'write-file': {
@@ -127,10 +132,10 @@ export async function initializeBrowserFS({
127132
$type: 'sync-sandbox',
128133
$data: {},
129134
});
135+
} else {
136+
resolve();
130137
}
131138

132-
resolve();
133-
134139
// BrowserFS is initialized and ready-to-use!
135140
});
136141
});

packages/app/src/app/overmind/effects/vscode/sandboxFsSync/index.ts

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,15 @@ class SandboxFsSync {
4242
private types: any;
4343
private typesInfo: Promise<any>;
4444
private initializingWorkers = blocker<void>();
45-
private workersInitializedCount = 0;
4645
public initialize(options: SandboxFsSyncOptions) {
4746
this.options = options;
4847
self.addEventListener('message', evt => {
49-
// We do not want to send initial sandbox until
50-
// all 3 filesystems are running
51-
if (this.initializingWorkers.isResolved()) {
52-
if (evt.data.$type === 'sync-types') {
53-
this.syncDependencyTypings();
54-
}
55-
56-
if (evt.data.$type === 'sync-sandbox') {
57-
this.syncSandbox();
58-
}
59-
} else if (evt.data.$type === 'sync-sandbox') {
60-
this.workersInitializedCount++;
48+
if (evt.data.$type === 'sync-types') {
49+
this.syncDependencyTypings();
50+
}
6151

62-
if (this.workersInitializedCount === 3) {
63-
this.initializingWorkers.resolve();
64-
}
52+
if (evt.data.$type === 'sync-sandbox') {
53+
this.syncSandbox();
6554
}
6655
});
6756

@@ -185,7 +174,7 @@ class SandboxFsSync {
185174

186175
private syncSandbox() {
187176
// eslint-disable-next-line
188-
console.log('## SYNCING SANDBOX AND TYPINGS WITH WORKERS');
177+
console.log('## SYNCING SANDBOX WITH WORKERS');
189178
this.send('sandbox-fs', json(this.options.getSandboxFs()));
190179
}
191180

@@ -221,6 +210,8 @@ class SandboxFsSync {
221210
syncDetails.packageJsonContent,
222211
syncDetails.autoInstall
223212
);
213+
// eslint-disable-next-line
214+
console.log('## SYNCING TYPES WITH WORKERS');
224215
this.sendTypes();
225216
}
226217
}

0 commit comments

Comments
 (0)