CommandBus
Αυτό το περιεχόμενο δεν είναι ακόμη διαθέσιμο στη γλώσσα σου.
Defined in: packages/cqrs/src/command.bus.ts:18
Sends a command to its one handler, through the handler’s pipeline. createCqrs()
builds it.
Example
Section titled “Example”const { commandBus } = createCqrs();const id = await commandBus.execute<CreateUserCommand, string>(new CreateUserCommand('ann'));Type Parameters
Section titled “Type Parameters”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new CommandBus<
C>(handlers):CommandBus<C>
Defined in: packages/cqrs/src/command.bus.ts:24
Parameters
Section titled “Parameters”handlers
Section titled “handlers”ReadonlyMap<AnyClass, Dispatch>
Maps each command class to the function that runs its handler. The bus reads it at every call, so it can be filled after the bus is created, as handlers that inject the bus require.
Returns
Section titled “Returns”CommandBus<C>
Methods
Section titled “Methods”execute()
Section titled “execute()”execute<
T,R>(command):Promise<R>
Defined in: packages/cqrs/src/command.bus.ts:37
Runs the handler of the command’s class, or of its nearest parent class that has
one, and resolves with what the handler returns, typed as R.
Type Parameters
Section titled “Type Parameters”T extends ICommand
R = unknown
Parameters
Section titled “Parameters”command
Section titled “command”T
Returns
Section titled “Returns”Promise<R>
Throws
Section titled “Throws”CommandHandlerNotFoundException (as a rejection) when no class in the command’s chain has a handler.
Example
Section titled “Example”await commandBus.execute(new CreateUserCommand('ann'));