Skip to content

Commit

Permalink
Refactor import/exportConfigs
Browse files Browse the repository at this point in the history
  • Loading branch information
baku89 committed Jun 13, 2024
1 parent 9396689 commit 3af36d5
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions core/src/Tethr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ export abstract class Tethr
await Promise.all(
ConfigNameList.map(async name => {
const desc = await this.getDesc(name)
if (desc.value === null) return null
// Export only writable configs
if (desc.value === null || !desc.writable) return null
return [name, desc.value] as const
})
)
Expand All @@ -145,22 +146,11 @@ export abstract class Tethr
* Apply all writable configs.
*/
async importConfigs(configs: Partial<ConfigType>) {
const sortedConfigs = Object.entries(configs).sort(([a], [b]) => {
const ai = ConfigNameList.indexOf(a as ConfigName)
const bi = ConfigNameList.indexOf(b as ConfigName)
return ai - bi
}) as [ConfigName, ConfigType[ConfigName]][]

for (const [name, value] of sortedConfigs) {
// NOTE: this might be converted to parallel execution in the future
try {
await this.set(name, value)
} finally {
null
}

// The delay is necessary to avoid "busy" error
// await sleep(25)
for (const name of ConfigNameList) {
const value = configs[name]
if (value === undefined) continue

await this.set(name, value)
}
}

Expand Down

0 comments on commit 3af36d5

Please sign in to comment.