Rewrite AppDomain to handle uncaughts & promises
This commit is contained in:
+46
-40
@@ -1,49 +1,55 @@
|
||||
"use strict";
|
||||
// The Package Loader
|
||||
|
||||
var fs = require( "fs" );
|
||||
var rootNS = {
|
||||
botanss: "./"
|
||||
};
|
||||
const fs = require( "fs" );
|
||||
const cluster = require( "cluster" );
|
||||
|
||||
var Package = function() { };
|
||||
|
||||
Package.prototype.rootNS = function( name, path )
|
||||
class Package
|
||||
{
|
||||
if( rootNS[ name ] ) return;
|
||||
rootNS[ name ] = fs.realpathSync( path ) + "/";
|
||||
};
|
||||
|
||||
var _reload = function( e, filename )
|
||||
{
|
||||
if( this._lock == global.X_SERVER_CLUSTER.worker.id )
|
||||
return;
|
||||
this._lock = global.X_SERVER_CLUSTER.worker.id;
|
||||
|
||||
setTimeout( () =>
|
||||
constructor()
|
||||
{
|
||||
global.Dragonfly.Info( `Change detected: ${this.src}, reloading` );
|
||||
global.X_SERVER_CLUSTER.worker.destroy();
|
||||
} , 200 );
|
||||
};
|
||||
|
||||
Package.prototype.load = function( _class )
|
||||
{
|
||||
var fSep = _class.indexOf( "." );
|
||||
var nsdomain = _class.substr( 0, fSep );
|
||||
_class = _class.substr( fSep + 1 ).replace( /\./g, "/" );
|
||||
|
||||
var file = rootNS[ nsdomain ] + _class;
|
||||
|
||||
if( global.debug && global.X_SERVER_CLUSTER && global.X_SERVER_CLUSTER.worker )
|
||||
{
|
||||
var src = require.resolve( file );
|
||||
if(!( src in require.cache ))
|
||||
{
|
||||
fs.watch( src, _reload.bind({ "src": src }) );
|
||||
}
|
||||
this._rootNS = { botanss: "./" };
|
||||
}
|
||||
|
||||
return require( file );
|
||||
};
|
||||
rootNS( name, path )
|
||||
{
|
||||
if( this._rootNS[ name ] ) return;
|
||||
this._rootNS[ name ] = fs.realpathSync( path ) + "/";
|
||||
}
|
||||
|
||||
load( _class )
|
||||
{
|
||||
var fSep = _class.indexOf( "." );
|
||||
var nsdomain = _class.substr( 0, fSep );
|
||||
_class = _class.substr( fSep + 1 ).replace( /\./g, "/" );
|
||||
|
||||
var file = this._rootNS[ nsdomain ] + _class;
|
||||
|
||||
if( global.debug && cluster.worker )
|
||||
{
|
||||
var src = require.resolve( file );
|
||||
if(!( src in require.cache ))
|
||||
{
|
||||
fs.watch( src, this._reload.bind({ "src": src }) );
|
||||
}
|
||||
}
|
||||
|
||||
return require( file );
|
||||
}
|
||||
|
||||
_reload( e, filename )
|
||||
{
|
||||
if( this._lock == cluster.worker.id )
|
||||
return;
|
||||
this._lock = cluster.worker.id;
|
||||
|
||||
setTimeout( () =>
|
||||
{
|
||||
global.Dragonfly.Info( `Change detected: ${this.src}, reloading` );
|
||||
cluster.worker.disconnect();
|
||||
setTimeout( () => process.exit(0), 1000 ).unref();
|
||||
} , 200 );
|
||||
}
|
||||
}
|
||||
|
||||
global.botanLoader = new Package();
|
||||
|
||||
Reference in New Issue
Block a user