fix(shell): config: fix task race

This commit is contained in:
Il Harper 2024-03-05 12:51:27 +08:00
parent 4eeef19083
commit 92abde9af2
No known key found for this signature in database
GPG Key ID: 4B71FCA698E7E8EC

View File

@ -16,7 +16,7 @@ import type { ChronocatConfig, ChronocatCurrentConfig } from './configEntity'
let config: ChronocatCurrentConfig | undefined = undefined let config: ChronocatCurrentConfig | undefined = undefined
const loadConfig = async () => { const task = (async () => {
const configDir = join(baseDir, 'config') const configDir = join(baseDir, 'config')
const configPath = join(configDir, 'chronocat.yml') const configPath = join(configDir, 'chronocat.yml')
@ -52,10 +52,10 @@ const loadConfig = async () => {
const result = Object.assign({}, parsedConfig, parsedConfig.overrides?.[uin]) const result = Object.assign({}, parsedConfig, parsedConfig.overrides?.[uin])
if ('overrides' in result) delete result.overrides if ('overrides' in result) delete result.overrides
return result config = result
} })()
export const getConfig = async () => { export const getConfig = async () => {
if (!config) config = await loadConfig() await task
return config return config!
} }