From 700f308d6eaeab63ea178b8278e8502b60f22ccc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Thu, 30 May 2024 17:28:08 +0800 Subject: [PATCH] feat: wrap NT-Event --- src/common/utils/EventTask.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/common/utils/EventTask.ts diff --git a/src/common/utils/EventTask.ts b/src/common/utils/EventTask.ts new file mode 100644 index 00000000..d0df4c00 --- /dev/null +++ b/src/common/utils/EventTask.ts @@ -0,0 +1,33 @@ +import { randomUUID } from "crypto"; +export interface NTEventType { + EventName: string, + EventFunction: Function, + ListenerName: string, + ListenerFunction: Function +} +export class NTEvent { + EventData: NTEventType; + EventTask: Map = new Map(); + constructor(params: NTEventType) { + params.ListenerFunction = this.DispatcherListener; + this.EventData = params; + } + async DispatcherListener(...args: any[]) { + for (let task of this.EventTask.values()) { + if (task instanceof Promise) { + await task(...args); + } + task(...args); + } + } + async Call(params: T & { checker?: Function }) { + + } + async CallWaitTwice(params: T & { checker?: Function }) { + + } + async CallWaitVoid(param: T & { checker?: Function }) { + + } +} +