From 7a1a1089e78d68b6691552a336ff787895ee8a85 Mon Sep 17 00:00:00 2001 From: killagu Date: Sun, 29 Jan 2023 22:05:43 +0800 Subject: [PATCH] fix: should not notify backgroundTaskHelper if teggContext not exists --- plugin/tegg/app.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugin/tegg/app.ts b/plugin/tegg/app.ts index 19a6d462..8469b777 100644 --- a/plugin/tegg/app.ts +++ b/plugin/tegg/app.ts @@ -8,6 +8,8 @@ import { EggContextCompatibleHook } from './lib/EggContextCompatibleHook'; import { CompatibleUtil } from './lib/CompatibleUtil'; import { ModuleHandler } from './lib/ModuleHandler'; import { EggContextHandler } from './lib/EggContextHandler'; +import { TEGG_CONTEXT } from '@eggjs/egg-module-common'; +import { TEggPluginContext } from './app/extend/context'; export default class App { private readonly app: Application; @@ -31,7 +33,10 @@ export default class App { async didLoad() { const eggRunInBackground = this.app.context.runInBackground; - this.app.context.runInBackground = function runInBackground(this: Context, scope: (ctx: Context) => Promise) { + this.app.context.runInBackground = function runInBackground(this: TEggPluginContext, scope: (ctx: Context) => Promise) { + if (!this[TEGG_CONTEXT]) { + return Reflect.apply(eggRunInBackground, this, [ scope ]); + } let resolveBackgroundTask; const backgroundTaskPromise = new Promise(resolve => { resolveBackgroundTask = resolve;