Skip to content

Commit

Permalink
docs(): add in-code documentation regarding the solution taken
Browse files Browse the repository at this point in the history
  • Loading branch information
micalevisk committed Oct 15, 2021
1 parent a72c686 commit 3fd95e1
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/bull.explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,19 @@ export class BullExplorer implements OnModuleInit {
.getProviders()
.filter((wrapper: InstanceWrapper) =>
this.metadataAccessor.isQueueComponent(
wrapper.inject || !wrapper.metatype
// NOTE: Regarding the ternary statement below,
// - The condition `!wrapper.metatype` is because when we use `useValue`
// the value of `wrapper.metatype` will be `null`.
// - The condition `wrapper.inject` is needed here because when we use
// `useFactory`, the value of `wrapper.metatype` will be the supplied
// factory function.
// For both cases, we should use `wrapper.instance.constructor` instead
// of `wrapper.metatype` to resolve processor's class properly.
// But since calling `wrapper.instance` could degrade overall performance
// we must defer it as much we can. But there's no other way to grab the
// right class that could be annotated with `@Processor()` decorator
// without using this property.
!wrapper.metatype || wrapper.inject
? wrapper.instance?.constructor
: wrapper.metatype,
),
Expand All @@ -45,6 +57,8 @@ export class BullExplorer implements OnModuleInit {
name: queueName,
} =
this.metadataAccessor.getQueueComponentMetadata(
// NOTE: We are relying on `instance.constructor` to properly support
// `useValue` and `useFactory` providers besides `useClass`.
instance.constructor || metatype,
);

Expand Down

0 comments on commit 3fd95e1

Please sign in to comment.