import { find } from 'lodash' ; import { ProcessId , ProcessOptions , IProcess , DefaultProcess } from '@lib/process/process' ; import { Runners } from '@lib/process/runners' ; import pool from '@lib/process/pool' ; export class ProcessFactory { param options param poolId public static make ( options , poolId ? ) { let spawned = null ; if ( options . forceRunner ) { const Runner = find ( Runners , runner => runner . type === options . forceRunner ) ; if ( Runner ) { spawned = new Runner ( options ) ; } } else { for ( let i = 0 ; i < Runners . length ; i ++ ) { if ( Runners [ i ] . owns ( options . command ) ) { spawned = new Runners [ i ] ( options ) ; } } } spawned = spawned || new DefaultProcess ( options ) ; pool . add ( spawned , poolId ) ; return spawned ; } }