total5 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +211 -0
- package/README.md +32 -0
- package/api.js +297 -0
- package/bin/flow5 +142 -0
- package/bin/total5 +245 -0
- package/builders.js +1770 -0
- package/bundles.js +447 -0
- package/cache.js +58 -0
- package/changelog.txt +5 -0
- package/cluster.js +320 -0
- package/cms.js +759 -0
- package/controller.js +1640 -0
- package/cron.js +99 -0
- package/debug.js +546 -0
- package/edit.js +462 -0
- package/error.html +49 -0
- package/filestorage.js +1109 -0
- package/flow-flowstream.js +3352 -0
- package/flow.js +238 -0
- package/flowstream.js +2061 -0
- package/global.js +274 -0
- package/htmlparser.js +662 -0
- package/http.js +83 -0
- package/image.js +777 -0
- package/images.js +747 -0
- package/index.js +2851 -0
- package/jsonschema.js +699 -0
- package/ldap.js +792 -0
- package/macros.js +222 -0
- package/mail.js +922 -0
- package/markdown.js +762 -0
- package/minificators.js +858 -0
- package/nosql-builder.js +440 -0
- package/nosql-querybuilder.js +320 -0
- package/nosql-reader.js +353 -0
- package/nosql-stream.js +617 -0
- package/nosql.js +782 -0
- package/openclient.js +219 -0
- package/package.json +14 -5
- package/pause.html +67 -0
- package/querybuilder.js +1220 -0
- package/release.js +167 -0
- package/routing.js +1028 -0
- package/sourcemap.js +163 -0
- package/tangular.js +409 -0
- package/templates.js +145 -0
- package/test.js +51 -0
- package/tms.js +380 -0
- package/uibuilder.js +242 -0
- package/utils.js +6432 -0
- package/viewengine.js +891 -0
- package/websocket.js +1944 -0
- package/workers.js +129 -0
package/workers.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// Total.js Workers
|
|
2
|
+
// The MIT License
|
|
3
|
+
// Copyright 2020-2023 (c) Peter Širka <petersirka@gmail.com>
|
|
4
|
+
|
|
5
|
+
const HEADER = { cwd: '' };
|
|
6
|
+
|
|
7
|
+
function process_thread() {
|
|
8
|
+
|
|
9
|
+
if (F.worker)
|
|
10
|
+
return F.worker;
|
|
11
|
+
|
|
12
|
+
F.dir(process.cwd());
|
|
13
|
+
|
|
14
|
+
const Port = F.Worker.parentPort;
|
|
15
|
+
|
|
16
|
+
F.worker = {};
|
|
17
|
+
F.worker.data = Port ? F.Worker.workerData : {};
|
|
18
|
+
F.worker.message = NOOP;
|
|
19
|
+
F.worker.isfork = !!Port;
|
|
20
|
+
F.worker.is = process.argv.indexOf('--worker') !== -1;
|
|
21
|
+
F.worker.setTimeout = function(timeout) {
|
|
22
|
+
F.worker.$timeout && clearTimeout(F.worker.$timeout);
|
|
23
|
+
F.worker.$timeout = setTimeout(() => F.worker.exit(1), timeout);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
F.worker.postMessage = F.worker.send = function() {
|
|
27
|
+
if (Port)
|
|
28
|
+
Port.postMessage.apply(Port, arguments);
|
|
29
|
+
else
|
|
30
|
+
process.send.apply(process, arguments);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
F.worker.exit = F.worker.kill = F.worker.close = function(code) {
|
|
34
|
+
process.exit(code || 0);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
var onmessage = function() {
|
|
38
|
+
F.worker.message && F.worker.message.apply(this, arguments);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
if (Port)
|
|
42
|
+
Port.on('message', onmessage);
|
|
43
|
+
else
|
|
44
|
+
process.on('message', onmessage);
|
|
45
|
+
|
|
46
|
+
return F.worker;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
exports.createthread = function(name, data) {
|
|
50
|
+
if (!name)
|
|
51
|
+
return process_thread();
|
|
52
|
+
var filename = name[0] === '~' ? name.substring(1) : F.path.root('workers/' + name + '.js');
|
|
53
|
+
var worker = new F.Worker.Worker(filename, { workerData: data, cwd: HEADER, argv: ['--worker'] });
|
|
54
|
+
worker.kill = worker.exit = () => worker.terminate();
|
|
55
|
+
return worker;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
exports.createfork = function(name) {
|
|
59
|
+
|
|
60
|
+
if (!name)
|
|
61
|
+
return process_thread();
|
|
62
|
+
|
|
63
|
+
var filename = name[0] === '~' ? name.substring(1) : F.path.root('workers/' + name + '.js');
|
|
64
|
+
var fork = new F.Child.fork(filename, { cwd: HEADER, argv: ['--worker'] });
|
|
65
|
+
fork.postMessage = fork.send;
|
|
66
|
+
fork.terminate = () => fork.kill('SIGTERM');
|
|
67
|
+
return fork;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
exports.createpool = function(name, count, isfork) {
|
|
71
|
+
|
|
72
|
+
var pool = {};
|
|
73
|
+
pool.workers = [];
|
|
74
|
+
pool.pending = [];
|
|
75
|
+
pool.count = pool;
|
|
76
|
+
pool.next = function() {
|
|
77
|
+
for (let worker of pool.workers) {
|
|
78
|
+
if (worker.$released) {
|
|
79
|
+
let fn = pool.pending.shift();
|
|
80
|
+
if (fn) {
|
|
81
|
+
worker.removeAllListeners('message');
|
|
82
|
+
worker.$released = false;
|
|
83
|
+
fn.call(worker, worker, worker.release);
|
|
84
|
+
} else
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
F.workers[name] = pool;
|
|
91
|
+
|
|
92
|
+
var release = function(worker) {
|
|
93
|
+
worker.on('exit', function() {
|
|
94
|
+
let index = pool.workers.indexOf(worker);
|
|
95
|
+
pool.workers.splice(index, 1);
|
|
96
|
+
let worker = isfork ? exports.createfork(name) : exports.createthread(name);
|
|
97
|
+
worker.$pool = pool;
|
|
98
|
+
worker.release = release(worker);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
return function() {
|
|
102
|
+
worker.$released = true;
|
|
103
|
+
worker.$pool.next();
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
for (var i = 0; i < count; i++) {
|
|
109
|
+
var worker = isfork ? exports.createfork(name) : exports.createthread(name);
|
|
110
|
+
worker.$pool = pool;
|
|
111
|
+
worker.$released = true;
|
|
112
|
+
worker.release = release(worker);
|
|
113
|
+
pool.workers.push(worker);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
pool.exec = function(fn) {
|
|
117
|
+
if (fn) {
|
|
118
|
+
pool.pending.push(fn);
|
|
119
|
+
pool.next();
|
|
120
|
+
} else {
|
|
121
|
+
return new Promise(function(resolve) {
|
|
122
|
+
pool.pending.push(resolve);
|
|
123
|
+
pool.next();
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
return pool;
|
|
129
|
+
};
|