-
Notifications
You must be signed in to change notification settings - Fork 0
/
native.process.js
95 lines (85 loc) · 2.39 KB
/
native.process.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* global __proc, nil, _proc */
var proc = {
_: _proc,
interval: 500,
list: [],
cache: [],
tmr: null,
act: false,
buf: {
current: "",
path: ""
},
path: function () {
if (this.buf.path !== "") {
return this.buf.path;
}
if (this.buf.current === "") {
this.buf.current = this._.current();
}
this.buf.path = this.buf.current.ignorelastDelimiter("/");
return this.buf.path;
},
enum: function () {
this.cache = this._.list().toString().parse();
return this.cache;
},
exists: function (p) {
if (this.enum().indexOf(p) > -1) {
return true;
}
return false;
},
current: function () {
if (this.buf.current !== "") {
return this.buf.current;
}
this.buf.current = this._.current();
return this.buf.current;
},
add: function (e, cb) {
var T = this;
e.cb = cb;
T.list.push(e);
if (!T.act) {
T.act = true;
T.tmr = setInterval(function () {
T.list.forEach(function (i, k) {
if (typeof i !== "undefined") {
if (i.running === true) {
if ((T._.ping(i.id)) === 0) {
T.list[k].cb(i.path);
T.list[k].running = false;
T._.release(i.id);
}
} else {
delete T.list[k];
}
}
});
}, T.interval);
}
}
};
var process = function () {
var T = this;
const api = proc;
T.meta = {};
T.create = function (path, onCreate, onClose) {
if (typeof onCreate === "undefined")
onCreate = nil;
if (typeof onClose === "undefined")
onClose = nil;
var params = "";
T.meta = JSON.parse(T._.create(path, params, 0));
if (T.meta.running === true) {
onCreate(T.meta.pid);
T.meta.path = path;
proc.add(T.meta, onClose);
return true;
} else {
return false;
}
};
return T;
};