Skip to content

Commit bca305e

Browse files
committed
Better parallelism
1 parent 29f1784 commit bca305e

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

.changeset/nervous-fishes-scream.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@code-hike/lighter": patch
3+
---
4+
5+
Better parallelism

lib/dist/index.cjs.js

+8-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/dist/index.esm.mjs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,7 @@ const lighter = {
11941194
registry: null,
11951195
aliasToScope: new Map(),
11961196
scopeToGrammar: new Map(),
1197+
scopeToPromise: new Map(),
11971198
};
11981199

11991200
function newRegistry() {
@@ -1208,8 +1209,9 @@ async function loadGrammars(alias) {
12081209
lighter.registry = newRegistry();
12091210
}
12101211

1211-
// if alias is registered, return
12121212
if (lighter.aliasToScope.has(alias)) {
1213+
const scope = lighter.aliasToScope.get(alias);
1214+
await lighter.scopeToPromise.get(scope);
12131215
return;
12141216
}
12151217

@@ -1227,7 +1229,11 @@ async function loadGrammars(alias) {
12271229
});
12281230

12291231
await Promise.all(
1230-
newGrammars.map((g) => lighter.registry.loadGrammar(g.scopeName))
1232+
newGrammars.map((g) => {
1233+
const promise = lighter.registry.loadGrammar(g.scopeName);
1234+
lighter.scopeToPromise.set(g.scopeName, promise);
1235+
return promise;
1236+
})
12311237
);
12321238
}
12331239

lib/src/registry.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const lighter = {
1010
registry: null,
1111
aliasToScope: new Map(),
1212
scopeToGrammar: new Map(),
13+
scopeToPromise: new Map(),
1314
};
1415

1516
export function newRegistry() {
@@ -24,8 +25,9 @@ export async function loadGrammars(alias) {
2425
lighter.registry = newRegistry();
2526
}
2627

27-
// if alias is registered, return
2828
if (lighter.aliasToScope.has(alias)) {
29+
const scope = lighter.aliasToScope.get(alias);
30+
await lighter.scopeToPromise.get(scope);
2931
return;
3032
}
3133

@@ -43,7 +45,11 @@ export async function loadGrammars(alias) {
4345
});
4446

4547
await Promise.all(
46-
newGrammars.map((g) => lighter.registry.loadGrammar(g.scopeName))
48+
newGrammars.map((g) => {
49+
const promise = lighter.registry.loadGrammar(g.scopeName);
50+
lighter.scopeToPromise.set(g.scopeName, promise);
51+
return promise;
52+
})
4753
);
4854
}
4955

0 commit comments

Comments
 (0)