Skip to content

Commit

Permalink
Run own or immediately extended beforeQueue (#1475)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima authored Sep 25, 2023
1 parent 1938e71 commit 232587e
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/actions/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,25 @@ export abstract class TasksMixin {
*/
async queueTasks(this: BaseGeneratorImpl): Promise<void> {
const thisAny = this as any;
const thisPrototype = Object.getPrototypeOf(thisAny);

let beforeQueueCallback: (() => Promise<any>) | undefined;
if (this.features.taskPrefix) {
// We want beforeQueue if beforeQueue belongs to the object or to the imediatelly extended class.
beforeQueueCallback =
Object.hasOwn(thisAny, 'beforeQueue') || Object.hasOwn(thisPrototype, 'beforeQueue')
? thisAny.beforeQueue
: undefined;
}

if (!beforeQueueCallback) {
// Fallback to _beforeQueue,
beforeQueueCallback =
Object.hasOwn(thisAny, '_beforeQueue') || Object.hasOwn(thisPrototype, '_beforeQueue')
? thisAny._beforeQueue
: undefined;
}

const beforeQueueCallback: () => Promise<any> =
(this.features.taskPrefix && thisAny.beforeQueue) ?? thisAny._beforeQueue;
if (beforeQueueCallback) {
await beforeQueueCallback.call(this);
}
Expand Down

0 comments on commit 232587e

Please sign in to comment.