silverbullet/plug-api/syscalls/event.ts

30 lines
655 B
TypeScript
Raw Normal View History

import { syscall } from "../syscall.ts";
2022-04-01 23:07:08 +08:00
2022-10-14 21:11:33 +08:00
export function dispatchEvent(
eventName: string,
data: any,
timeout?: number,
): Promise<any[]> {
return new Promise((resolve, reject) => {
let timeouter: any = -1;
if (timeout) {
timeouter = setTimeout(() => {
console.log("Timeout!");
reject("timeout");
}, timeout);
}
syscall("event.dispatch", eventName, data)
2024-07-30 23:24:17 +08:00
.then((r: any) => {
if (timeouter !== -1) {
clearTimeout(timeouter);
}
resolve(r);
})
.catch(reject);
});
2022-04-01 23:07:08 +08:00
}
export function listEvents(): Promise<string[]> {
return syscall("event.list");
}