-
Notifications
You must be signed in to change notification settings - Fork 0
/
fork-it.js
executable file
·79 lines (67 loc) · 1.39 KB
/
fork-it.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
var logger = require('./lib/helpers/logHelper.js');
var proc = require('./lib/helpers/procHelper.js');
//Setup the Global Config Object with defaults
global.forkIt = {};
global.forkIt.config = {
logging: {
threshold: "error"
}
}
var forkIt = function() {
var ipcBus = require('./lib/ipc/ipcBus');
var ipcBusObj = {};
/*
Description: Forks a Process
Params
- File: relative path to the file
Throws
- File Not Specified
*/
function fork(path, file ,obj , cb) {
if (!file) {
throw "File to Fork not specified";
}
var processObj = proc.fork(path, file);
ipcBusObj = new ipcBus(processObj, obj, cb);
}
/*
Description: This method initializes the child object
Params
- obj: object that will be shared to the parent process
- cb: callback one the IPC bus has been instantiated
Throws
- File Not Specified
*/
function initChild(obj, cb) {
if(!obj)
throw "Cannot pass a null object";
ipcBusObj = new ipcBus(process, obj, cb);
}
/*
Description: Child Process Object
Params
-
Throws
-
*/
function child() {
return ipcBusObj.Stub();
}
/*
Description: Parent Process Object
Params
-
Throws
-
*/
function parent() {
return ipcBusObj.Stub();
}
return {
fork: fork,
child: child,
parent: parent,
initChild: initChild
};
}
module.exports = forkIt();