Skip to content

Commit

Permalink
fix: data race
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed May 15, 2024
1 parent d751238 commit d5b6ec3
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions composables/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ watch(
const parserContextCache: Record<string, unknown> = Object.create(null)
async function initParser() {
const { pkgName, init } = currentParser.value
const pkgId = `${pkgName}${overrideVersion.value ? `@${overrideVersion.value}` : ''}`
const pkgId = `${pkgName}${
overrideVersion.value ? `@${overrideVersion.value}` : ''
}`
if (parserContextCache[pkgId]) return parserContextCache[pkgId]
return (parserContextCache[pkgId] = await init?.(pkgId))
}
Expand All @@ -129,9 +131,12 @@ watch(
displayVersion.value = parser.version
} else {
displayVersion.value = ''
displayVersion.value = await Promise.resolve(
const res = await Promise.resolve(
parser.version.call(parserContextPromise.value, parser.pkgName),
)
if (currentParser.value.id === parser.id) {
displayVersion.value = res
}
}
},
{ immediate: true },
Expand All @@ -141,8 +146,10 @@ watch(
[parserContextPromise, currentParser, code, rawOptions],
async () => {
try {
const id = currentParser.value.id
loading.value = 'load'
const ctx = await parserContextPromise.value
if (currentParser.value.id !== id) return
loading.value = 'parse'
const t = window.performance.now()
ast.value = await currentParser.value.parse.call(
Expand Down

0 comments on commit d5b6ec3

Please sign in to comment.