OtherModule.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { UniqueMethods } from "../types/Modules";
  2. import BaseModule from "../BaseModule";
  3. import ModuleManager from "../ModuleManager";
  4. export default class OtherModule extends BaseModule {
  5. /**
  6. * Other Module
  7. *
  8. * @param moduleManager - Module manager class
  9. */
  10. public constructor(moduleManager: ModuleManager) {
  11. super(moduleManager, "others");
  12. }
  13. /**
  14. * startup - Startup other module
  15. */
  16. public override startup(): Promise<void> {
  17. return new Promise((resolve, reject) => {
  18. super
  19. .startup()
  20. .then(() => {
  21. console.log("Other Startup");
  22. super.started();
  23. resolve();
  24. })
  25. .catch(err => reject(err));
  26. });
  27. }
  28. /**
  29. * doThing - Do thing
  30. *
  31. * @param payload - Payload
  32. * @returns Returned object
  33. */
  34. public doThing(payload: { test: string; test2: number }): Promise<{
  35. res: number;
  36. }> {
  37. return new Promise((resolve, reject) => {
  38. const { test, test2 } = payload;
  39. // console.log("doThing", test, test2);
  40. setTimeout(
  41. () =>
  42. Math.round(Math.random())
  43. ? resolve({ res: 123 })
  44. : reject(),
  45. Math.random() * 1000
  46. );
  47. });
  48. }
  49. }
  50. export type OtherModuleJobs = {
  51. [Property in keyof UniqueMethods<OtherModule>]: {
  52. payload: Parameters<UniqueMethods<OtherModule>[Property]>[0];
  53. returns: Awaited<ReturnType<UniqueMethods<OtherModule>[Property]>>;
  54. };
  55. };