Add foreground service, some cleanup, and start websocket server
This commit is contained in:
24
src/service/Foreground.ts
Normal file
24
src/service/Foreground.ts
Normal 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?.()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user