import { spawn , Resource } from 'effection' ; import { exec , Process , ExecOptions , ExitStatus , DaemonExitError } from './exec' ; /**
 * Start a long-running process, like a web server that run perpetually.
 * Daemon operations are expected to run forever, and if they exit pre-maturely
 * before the operation containing them passes out of scope it raises an error.
 */ export interface Daemon extends Resource < Process > { } export function daemon ( command , options = { } ) { return { name : `daemon(${ JSON . stringify ( command ) })` , labels : { expand : false } , * init ( ) { let process = yield exec ( command , options ) ; yield spawn ( function * failOnExit ( ) { let status = yield process . join ( ) ; throw new DaemonExitError ( status , command , options ) ; } ) ; return process ; } } ; }