Skip to content

Commit

Permalink
feat(core): handle dispose error
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Mar 12, 2021
1 parent 00f9c46 commit bf18011
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
13 changes: 7 additions & 6 deletions packages/koishi-core/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,15 @@ export class Context {
const state = this.app.registry.get(plugin)
if (!state) return
if (state.sideEffect) throw new Error('plugins with side effect cannot be disposed')
await Promise.all([
await Promise.allSettled([
...state.children.slice().map(plugin => this.dispose(plugin)),
...state.disposables.map(dispose => dispose()),
])
this.app.registry.delete(plugin)
const index = state.parent.children.indexOf(plugin)
if (index >= 0) state.parent.children.splice(index, 1)
this.emit('registry', this.app.registry)
]).finally(() => {
this.app.registry.delete(plugin)
const index = state.parent.children.indexOf(plugin)
if (index >= 0) state.parent.children.splice(index, 1)
this.emit('registry', this.app.registry)
})
}

async parallel<K extends EventName>(name: K, ...args: Parameters<EventMap[K]>): Promise<Await<ReturnType<EventMap[K]>>[]>
Expand Down
2 changes: 2 additions & 0 deletions packages/koishi-core/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export class Session<
readonly sid: string
uid: string
cid: string
gid: string

id?: string
argv?: Argv<U, G>
Expand All @@ -119,6 +120,7 @@ export class Session<
defineProperty(this, 'sid', `${this.platform}:${this.selfId}`)
defineProperty(this, 'uid', `${this.platform}:${this.userId}`)
defineProperty(this, 'cid', `${this.platform}:${this.channelId}`)
defineProperty(this, 'gid', `${this.platform}:${this.groupId}`)
defineProperty(this, 'bot', app.bots[this.sid])
defineProperty(this, 'id', Random.uuid())
defineProperty(this, '_queued', Promise.resolve())
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es2019",
"target": "es2020",
"module": "commonjs",
"declaration": true,
"emitDeclarationOnly": true,
Expand Down

0 comments on commit bf18011

Please sign in to comment.