Browse Source

Make ASWorker into module.

Bentley James Oakes 7 years ago
parent
commit
a4ac417797
3 changed files with 43 additions and 7 deletions
  1. 23 3
      __worker.js
  2. 17 3
      asworker.js
  3. 3 1
      mmmk.js

+ 23 - 3
__worker.js

@@ -497,9 +497,15 @@ process.on('message',
 
 			__wtype = msg['workerType'];
 			__wid   = msg['workerId'];
-			_wlib   = eval('('+_fs.readFileSync('.'+__wtype+'.js', 'utf8')+')');
-			_mmmk   = eval('('+_fs.readFileSync('./mmmk.js', 'utf8')+')');
-			_mt  	  = eval('('+_fs.readFileSync('./libmt.js', 'utf8')+')');
+
+			if (__wtype == "/asworker"){
+				_wlib = require("./asworker");
+			}else {
+                _wlib = eval('(' + _fs.readFileSync('.' + __wtype + '.js', 'utf8') + ')');
+			}
+			_mmmk   = require('./mmmk');
+
+            _mt  	  = eval('('+_fs.readFileSync('./libmt.js', 'utf8')+')');
 
 			_plugins = {};
 			_fs.readdirSync('./plugins').forEach(
@@ -826,3 +832,17 @@ function POST_batchedit(resp,reqData)
 			}
 	);
 }
+
+module.exports = {
+	__errorContinuable,
+	__successContinuable,
+	__httpReq,
+	__wHttpReq,
+
+	__postInternalErrorMsg,
+	__sequenceNumber,
+
+	__postMessage,
+	__uri_to_id
+
+};

+ 17 - 3
asworker.js

@@ -2,8 +2,22 @@
 *  Copyright 2011 by the AToMPM team and licensed under the LGPL
 *  See COPYING.lesser and README.md in the root of this project for full details
 */
-
-{
+const {
+    __errorContinuable,
+    __httpReq,
+    __postInternalErrorMsg, __postMessage,
+    __sequenceNumber,
+    __successContinuable,
+	__uri_to_id
+} = require("./__worker");
+
+const _do = require("./___do");
+const _utils = require('./utils');
+const _mmmk = require("./mmmk");
+const _fs = _do.convert(require('fs'), ['readFile', 'writeFile', 'readdir']);
+
+
+module.exports = {
 	/************************** REST REQUEST HANDLING **************************/
 	/* INTENT :
 			ask our mtworker to do something (e.g., change transformation execution
@@ -499,4 +513,4 @@
 					 'sequence#':__sequenceNumber(),
 					 'respIndex':resp});
 		}	
-}
+};

+ 3 - 1
mmmk.js

@@ -10,7 +10,9 @@
 		atom3 supported 'save' events as a hack to enable forcing mm validation...
 		in atompm, such validation is carried out by _mmmk.validateModel (which
 		clients can 'call') and thus, we do no support 'save' events... */
-{
+
+const _utils = require('./utils');
+module.exports = {
 	/********************************* GLOBALS *********************************/
 	'metamodels':{},
 	'model':{'nodes':{},'edges':[],'metamodels':[]},