Add foreground service, some cleanup, and start websocket server

This commit is contained in:
2022-07-13 21:35:18 -05:00
parent 4d7769de56
commit 6476416c67
12 changed files with 158 additions and 43 deletions

24
src/service/Foreground.ts Normal file
View File

@@ -0,0 +1,24 @@
import {Unit} from '../lifecycle/Unit'
import {Inject} from '../di'
import {Logging} from './Logging'
import * as process from 'process'
export class Foreground extends Unit {
@Inject()
protected readonly logging!: Logging
protected resolver?: () => unknown
public up(): Promise<void> {
return new Promise<void>(res => {
this.resolver = res
this.logging.success(`Application started! Press ^C or send SIGINT to stop.`)
process.stdin.resume()
process.on('SIGINT', res)
})
}
public down(): void {
this.resolver?.()
}
}