1
0
silverbullet/syscall/plugos-syscall/event.ts
Zef Hemel 561aa6891f
Migrate to Deno (#86)
Big bang migration to Deno 🤯
2022-10-10 14:50:21 +02:00

30 lines
644 B
TypeScript

import { syscall } from "./syscall.ts";
export function dispatch(
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)
.then((r) => {
if (timeouter !== -1) {
clearTimeout(timeouter);
}
resolve(r);
})
.catch(reject);
});
}
export function listEvents(): Promise<string[]> {
return syscall("event.list");
}