You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
691 B

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