1 | 'use strict'
|
2 |
|
3 | const Farm = require('./farm')
|
4 |
|
5 | let farms = []
|
6 |
|
7 |
|
8 | function 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 |
|
21 | return api
|
22 | }
|
23 |
|
24 |
|
25 | function 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, 'Worker farm not found!'))
|
30 | }
|
31 |
|
32 |
|
33 | module.exports = farm
|
34 | module.exports.end = end |
\ | No newline at end of file |