2022-10-10 12:50:21 +00:00
|
|
|
import { syscall } from "./syscall.ts";
|
2022-04-01 15:07:08 +00:00
|
|
|
|
2022-10-14 13:11:33 +00:00
|
|
|
export function dispatchEvent(
|
2022-04-19 14:54:47 +00:00
|
|
|
eventName: string,
|
|
|
|
data: any,
|
2022-10-10 12:50:21 +00:00
|
|
|
timeout?: number,
|
2022-04-19 14:54:47 +00:00
|
|
|
): Promise<any[]> {
|
|
|
|
return new Promise((resolve, reject) => {
|
2022-04-20 08:56:43 +00:00
|
|
|
let timeouter: any = -1;
|
|
|
|
if (timeout) {
|
|
|
|
timeouter = setTimeout(() => {
|
|
|
|
console.log("Timeout!");
|
|
|
|
reject("timeout");
|
|
|
|
}, timeout);
|
|
|
|
}
|
2022-04-19 14:54:47 +00:00
|
|
|
syscall("event.dispatch", eventName, data)
|
|
|
|
.then((r) => {
|
2022-04-20 08:56:43 +00:00
|
|
|
if (timeouter !== -1) {
|
|
|
|
clearTimeout(timeouter);
|
|
|
|
}
|
2022-04-19 14:54:47 +00:00
|
|
|
resolve(r);
|
|
|
|
})
|
|
|
|
.catch(reject);
|
|
|
|
});
|
2022-04-01 15:07:08 +00:00
|
|
|
}
|
2022-07-04 13:07:27 +00:00
|
|
|
|
2022-10-10 12:50:21 +00:00
|
|
|
export function listEvents(): Promise<string[]> {
|
2022-07-04 13:07:27 +00:00
|
|
|
return syscall("event.list");
|
|
|
|
}
|