@tshio/command-bus
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

Command Bus

npm version

Non-blocking Command Bus library for Node.js.

This is a 100% JavaScript library, with TypeScript definition, with the Promise API.

Installing

$ npm install @tshio/command-bus

or

yarn add @tshio/command-bus

Usage

// CommonJS
const { Command, CommandBus, CommandHandler } = require('@tshio/command-bus');

// ES Module
import { Command, CommandBus, CommandHandler } from '@tshio/command-bus';


class TestHandler implements CommandHandler<Command<string>> {
  public commandType: string = "test-type";

  async execute(command: Command<string>) {
    return `handler-message ${command.payload}`;
  }
}


const bus = new CommandBus([new TestHandler()]);

const testCommand: Command<string> = {
  payload: "payload-data",
  type: "test-type",
};

const result = await bus.execute(testCommand);

console.log(result);

// => "handler-message payload-data"

License

license

This project is licensed under the terms of the MIT license.

About us:

The Software House

tsh.png

Readme

Keywords

none

Package Sidebar

Install

npm i @tshio/command-bus

Weekly Downloads

120

Version

1.0.4

License

MIT

Unpacked Size

12.2 kB

Total Files

12

Last publish

Collaborators

  • vviktor
  • aherok
  • sethii
  • barograf