chore: Add in the changes that where discussed with @Dr_Bonez in the room

This commit is contained in:
J H
2023-11-13 15:18:51 -07:00
parent e8684cbb9d
commit 46f594ab71
2 changed files with 8 additions and 5 deletions

View File

@@ -2,14 +2,14 @@ import * as T from "@start9labs/start-sdk/lib/types"
import * as net from "net"
import { CallbackHolder } from "./CallbackHolder"
const path = "/start9/sockets/rpcOut.sock"
const SOCKET_PATH = "/start9/sockets/startDaemon.sock"
const MAIN = "main" as const
export class Effects implements T.Effects {
constructor(readonly method: string, readonly callbackHolder: CallbackHolder) {}
id = 0
rpcRound(method: string, params: unknown) {
const id = this.id++;
const client = net.createConnection(path, () => {
const client = net.createConnection(SOCKET_PATH, () => {
client.write(JSON.stringify({
id,
method,

View File

@@ -16,6 +16,10 @@ import { CallbackHolder } from "./CallbackHolder"
import * as CP from "child_process"
import * as Mod from "module"
const SOCKET_PATH = "/start9/sockets/rpc.sock"
const LOCATION_OF_SERVICE_JS = "/services/service.js"
const childProcesses = new Map<number, CP.ChildProcess[]>()
let childProcessIndex = 0
const require = Mod.prototype.require
@@ -76,7 +80,6 @@ const cleanupRequire = (requireChildProcessIndex: number) => {
}
const idType = some(string, number)
const path = "/start9/sockets/rpc.sock"
const runType = object({
id: idType,
method: literal("run"),
@@ -104,7 +107,7 @@ const dealWithInput = async (callbackHolder: CallbackHolder, input: unknown) =>
const index = setupRequire()
const effects = new Effects(`/${methodName.join("/")}`, callbackHolder)
// @ts-ignore
return import("/services/service.js")
return import(LOCATION_OF_SERVICE_JS)
.then((x) => methodName.reduce(reduceMethod(methodArgs, effects), x))
.then()
.then((result) => ({ id, result }))
@@ -135,7 +138,7 @@ export class Runtime {
unixSocketServer = net.createServer(async (server) => {})
private callbacks = new CallbackHolder()
constructor() {
this.unixSocketServer.listen(path)
this.unixSocketServer.listen(SOCKET_PATH)
this.unixSocketServer.on("connection", (s) => {
s.on("data", (a) =>