Tons of progress

This commit is contained in:
Zef Hemel
2022-02-24 17:24:49 +01:00
parent aa7929ea29
commit 5e5968f09e
38 changed files with 1039 additions and 144 deletions
+9
View File
@@ -0,0 +1,9 @@
import {syscall} from "./syscall.ts";
export async function put(key: string, value: any) {
return await syscall("db.put", key, value);
}
export async function get(key: string) {
return await syscall("db.get", key);
}
+5
View File
@@ -0,0 +1,5 @@
import {syscall} from "./syscall.ts";
export async function publish(event: string, data?: object) {
return await syscall("event.publish", event, data);
}
+16
View File
@@ -0,0 +1,16 @@
export function syscall(name: string, ...args: Array<any>): any {
let reqId = Math.floor(Math.random() * 1000000);
// console.log("Syscall", name, reqId);
return new Promise((resolve, reject) => {
self.dispatchEvent(
new CustomEvent("syscall", {
detail: {
id: reqId,
name: name,
args: args,
callback: resolve,
},
}),
);
});
}