1'use strict' 2 3const Farm = require('./farm') 4 5let farms = [] // keep record of farms so we can end() them if required 6 7 8function farm (options, path, methods) { 9 if (typeof options == 'string') { 10 methods = path 11 path = options 12 options = {} 13 } 14 15 let f = new Farm(options, path) 16 , api = f.setup(methods) 17 18 farms.push({ farm: f, api: api }) 19 20 // return the public API 21 return api 22} 23 24 25function end (api, callback) { 26 for (let i = 0; i < farms.length; i++) 27 if (farms[i] && farms[i].api === api) 28 return farms[i].farm.end(callback) 29 process.nextTick(callback.bind(null, new Error('Worker farm not found!'))) 30} 31 32 33module.exports = farm 34module.exports.end = end 35