Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/services/nostr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,31 @@ export default class NostrSubprocess {
utils: Utils
awaitingPongs: (() => void)[] = []
log = getLogger({})
latestRestart = 0
constructor(settings: NostrSettings, utils: Utils, eventCallback: EventCallback, beaconCallback: BeaconCallback) {
this.utils = utils
this.startSubProcess(settings, eventCallback, beaconCallback)
}

startSubProcess(settings: NostrSettings, eventCallback: EventCallback, beaconCallback: BeaconCallback) {
this.childProcess = fork("./build/src/services/nostr/handler")
this.childProcess.on("error", (error) => {
this.log(ERROR, "nostr subprocess error", error)
})

this.childProcess.on("exit", (code, signal) => {
this.log(ERROR, `nostr subprocess exited with code ${code} and signal ${signal}`)
if (code === 0) {
this.log("nostr subprocess exited")
return
}
throw new Error(`nostr subprocess exited with code ${code} and signal ${signal}`)
this.log(ERROR, `nostr subprocess exited with code ${code} and signal ${signal}`)
const now = Date.now()
if (now - this.latestRestart < 1000 * 5) {
this.log(ERROR, "nostr subprocess exited too quickly")
throw new Error("nostr subprocess exited too quickly")
}
this.latestRestart = now
this.startSubProcess(settings, eventCallback, beaconCallback)
})

this.childProcess.on("message", (message: ChildProcessResponse) => {
Expand All @@ -50,6 +62,8 @@ export default class NostrSubprocess {
}
})
}


sendToChildProcess(message: ChildProcessRequest) {
this.childProcess.send(message)
}
Expand Down