total5 0.0.13-1 → 0.0.13-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.
Files changed (3) hide show
  1. package/global.js +4 -2
  2. package/package.json +1 -1
  3. package/pypeline.js +17 -35
package/global.js CHANGED
@@ -221,8 +221,10 @@ global.CLONE = F.TUtils.clone;
221
221
  global.COPY = F.TUtils.copy;
222
222
  global.QUERIFY = F.TUtils.querify;
223
223
  global.PYPELINE = function(name, options) {
224
- name = name[0] === '~' ? name.substring(1) : PATH.root('pypelines/' + name + '.py');
225
- return require('./pypeline').init(name, options);
224
+ let filename = name[0] === '~' ? name.substring(1) : PATH.root('pypelines/' + name + '.py');
225
+ let pypeline = require('./pypeline').init(filename, options);
226
+ pypeline.name = name;
227
+ return pypeline;
226
228
  };
227
229
 
228
230
  // TMS
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "total5",
3
- "version": "0.0.13-1",
3
+ "version": "0.0.13-2",
4
4
  "description": "Total.js framework v5",
5
5
  "main": "index.js",
6
6
  "directories": {
package/pypeline.js CHANGED
@@ -40,25 +40,15 @@ Pypeline.prototype.init = function() {
40
40
  let length = buffer.readUInt32BE(0);
41
41
  if (buffer.length >= length + 4) {
42
42
 
43
- let uid = buffer.readUInt32BE(4);
44
- let buf = buffer.subarray(8, 8 + length);
43
+ let buf = buffer.subarray(4, 4 + length);
45
44
 
46
45
  if (t.type === 'json')
47
46
  buf = buf.toString('utf8').parseJSON(true);
48
47
  else if (t.type === 'text')
49
48
  buf = buf.toString('utf8');
50
49
 
51
- if (uid) {
52
- let key = uid + '';
53
- let callback = t.callbacks[key];
54
- if (callback) {
55
- callback.fn(null, buf);
56
- delete t.callbacks[key];
57
- }
58
- } else
59
- t.emit('data', buf);
60
-
61
- buffer = buffer.subarray(8 + length);
50
+ t.emit('data', buf);
51
+ buffer = buffer.subarray(4 + length);
62
52
  } else
63
53
  break;
64
54
  }
@@ -84,16 +74,18 @@ Pypeline.prototype.init = function() {
84
74
  });
85
75
 
86
76
  let pending = t.pending.splice(0);
87
- for (let msg of pending)
88
- t.send(msg.data, msg.callback);
77
+ for (let data of pending)
78
+ t.send(data);
89
79
 
90
80
  t.emit('open');
91
81
 
92
82
  });
93
83
 
94
- t.server.listen(t.socket, function() {
95
- console.log('Pypeline connected:', t.filename);
96
- t.run();
84
+ Total.Fs.unlink(t.socket, function() {
85
+ t.server.listen(t.socket, function() {
86
+ console.log('Pypeline connected:', t.name);
87
+ t.run();
88
+ });
97
89
  });
98
90
  };
99
91
 
@@ -129,37 +121,27 @@ Pypeline.prototype.close = function() {
129
121
  return t;
130
122
  };
131
123
 
132
- Pypeline.prototype.send = function(data, callback) {
124
+ Pypeline.prototype.send = function(data) {
133
125
 
134
126
  let t = this;
127
+ let client = t.sockets[0];
135
128
 
136
- if (!t.sockets.length) {
137
- t.pending.push({ data: data, callback: callback });
129
+ if (!client) {
130
+ t.pending.push(data);
138
131
  return;
139
132
  }
140
133
 
141
- let client = t.sockets[0];
142
-
143
134
  /*
144
135
  let client = t.sockets[t.current++];
145
136
  if (t.current > t.sockets.length)
146
137
  t.current = 0;
147
138
  */
148
139
 
149
- let buffer = data instanceof Buffer ? data : Buffer.from(typeof(data) === 'object' ? JSON.stringify(data) : data, 'utf8');
140
+ let buffer = data instanceof Buffer ? data : Buffer.from(typeof(data) === 'object' ? JSON.stringify(data) : data.toString(), 'utf8');
150
141
  let size = Buffer.alloc(4);
151
- let uid = Buffer.alloc(4);
152
142
 
153
143
  size.writeUInt32BE(buffer.length);
154
-
155
- if (callback) {
156
- if (t.counter === 4294967295)
157
- t.counter = 0;
158
- uid.writeUInt32BE(t.counter++);
159
- t.callbacks[t.counter + ''] = { ts: Date.now(), fn: callback, socket: client };
160
- }
161
-
162
- client.write(Buffer.concat([size, uid, buffer]));
144
+ client.write(Buffer.concat([size, buffer]));
163
145
  return t;
164
146
  };
165
147
 
@@ -176,7 +158,7 @@ Pypeline.prototype.run = function() {
176
158
  } catch {}
177
159
  }
178
160
 
179
- t.process = Total.Child.spawn('python3', [t.filename, t.socket], { cwd: PATH.root(), stdio: ['inherit', 'inherit', 'inherit'] });
161
+ t.process = Total.Child.spawn('python3', ['-u', t.filename, t.socket], { cwd: PATH.root(), stdio: ['inherit', 'inherit', 'inherit'] });
180
162
 
181
163
  t.process.on('close', function() {
182
164
  if (t.autorestart) {