Skip to content

Commit

Permalink
feat(core): adjust bail/serial behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Sep 1, 2020
1 parent 6ffde4a commit f631856
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/koishi-core/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ function matchScope(base: ScopeSet, id: number) {
return !id || !(base.positive ^ base.includes(id))
}

function isBailed(value: any) {
return value !== null && value !== false && value !== undefined
}

export class Context {
static readonly MIDDLEWARE_EVENT = Symbol('mid')

Expand Down Expand Up @@ -140,7 +144,7 @@ export class Context {
for (const [context, callback] of this.app._hooks[name] || []) {
if (!context.match(session)) continue
const result = await callback.apply(this, args)
if (result !== undefined) return result
if (isBailed(result)) return result
}
}

Expand All @@ -153,7 +157,7 @@ export class Context {
for (const [context, callback] of this.app._hooks[name] || []) {
if (!context.match(session)) continue
const result = callback.apply(this, args)
if (result !== undefined) return result
if (isBailed(result)) return result
}
}

Expand Down

0 comments on commit f631856

Please sign in to comment.