Skip to content

Commit

Permalink
fix: Handle more error cases and remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed Apr 2, 2024
1 parent 4beae74 commit cb889c1
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 226 deletions.
10 changes: 0 additions & 10 deletions xmcl-keystone-ui/src/composables/extensionStyle.ts

This file was deleted.

1 change: 0 additions & 1 deletion xmcl-keystone-ui/src/composables/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export * from './i18n'
export * from './router'
export * from './saveLoad'
export * from './selectionList'
export * from './protocol'
export * from './service'
export * from './operation'
Expand Down
207 changes: 0 additions & 207 deletions xmcl-keystone-ui/src/composables/selectionList.ts

This file was deleted.

19 changes: 16 additions & 3 deletions xmcl-runtime/instanceIO/UnzipFileTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,32 @@ export class UnzipFileTask extends AbortableTask<void> {
this.#zipInstances[zip] = [zipInstance, reocrd]
}

const promises = [] as Promise<void>[]
const promises = [] as Promise<unknown>[]
for (const { zipPath, entryName, destination } of queue) {
const [zip, entries] = this.#zipInstances[zipPath]
const entry = entries[entryName]
if (entry) {
promises.push(this.#processEntry(zip, entry, destination))
promises.push(this.#processEntry(zip, entry, destination).catch((e) => {
return Object.assign(e, {
zipEntry: entry,
zipPath,
})
}))
}
}
await Promise.all(promises)
const errors = (await Promise.all(promises)).filter(e => !!e)

for (const [zipPath, [zip]] of Object.entries(this.#zipInstances)) {
zip.close()
}

if (errors.length > 0) {
if (errors.length > 1) {
throw new AggregateError(errors)
}

throw errors[0]
}
}

protected abort(isCancelled: boolean): void {
Expand Down
15 changes: 10 additions & 5 deletions xmcl-runtime/service/ServiceStateContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,16 @@ export class ServiceStateContainer<T = any> implements ServiceStateContext {
}

untrack(client: Client) {
const [[_, handler]] = this.#clients.splice(this.#clients.findIndex(c => c[0] === client), 1)
this.emitter.off('*', handler as any)
if (this.#clients.length === 0 && !this.#static) {
this.destroy()
return true
const index = this.#clients.findIndex(c => c[0] === client)
if (index === -1) return false
const deleted = this.#clients.splice(index, 1)
if (deleted[0]) {
const [_, handler] = deleted[0]
this.emitter.off('*', handler as any)
if (this.#clients.length === 0 && !this.#static) {
this.destroy()
return true
}
}
return false
}
Expand Down

0 comments on commit cb889c1

Please sign in to comment.