2018-07-18 06:33:23 +00:00
|
|
|
import * as consolecolor from '@pushrocks/consolecolor';
|
2018-07-17 21:12:12 +00:00
|
|
|
import * as smartpromise from '@pushrocks/smartpromise';
|
|
|
|
import { HrtMeasurement } from './early.hrtMeasurement';
|
2017-04-23 18:57:01 +00:00
|
|
|
|
2018-07-17 21:12:12 +00:00
|
|
|
export { HrtMeasurement };
|
2016-06-10 03:18:03 +00:00
|
|
|
|
2018-07-17 21:12:12 +00:00
|
|
|
let doText: boolean = false;
|
|
|
|
let moduleName: string = 'undefined module name';
|
|
|
|
let startHrt: HrtMeasurement;
|
2016-08-20 05:03:49 +00:00
|
|
|
|
2016-09-18 22:34:38 +00:00
|
|
|
if (process.argv.indexOf('-v') === -1) {
|
2018-07-17 21:12:12 +00:00
|
|
|
doText = true;
|
2016-06-10 03:18:03 +00:00
|
|
|
}
|
|
|
|
|
2016-09-18 22:34:38 +00:00
|
|
|
/**
|
|
|
|
* start the loading
|
|
|
|
*/
|
2018-07-17 21:12:12 +00:00
|
|
|
export let start = function(moduleNameArg: string = '', loaderLengthArg: string = '10') {
|
|
|
|
moduleName = moduleNameArg;
|
|
|
|
startHrt = new HrtMeasurement();
|
|
|
|
startHrt.start();
|
2017-02-17 17:56:58 +00:00
|
|
|
if (doText) {
|
2018-07-18 06:33:23 +00:00
|
|
|
console.log(`**** starting ${consolecolor.coloredString(moduleNameArg, 'green')} ****`);
|
2017-02-17 17:56:58 +00:00
|
|
|
}
|
2018-07-17 21:12:12 +00:00
|
|
|
};
|
2016-05-20 17:06:25 +00:00
|
|
|
|
2017-02-17 17:56:58 +00:00
|
|
|
export let stop = (): Promise<number> => {
|
2018-07-17 21:12:12 +00:00
|
|
|
let done = smartpromise.defer<number>();
|
|
|
|
let earlyExecutionTime = startHrt.stop().milliSeconds;
|
|
|
|
let earlyExecutionTimeString: string = (earlyExecutionTime / 1000).toString();
|
|
|
|
console.log(
|
2018-07-18 06:33:23 +00:00
|
|
|
`OK! -> finished loading within ${consolecolor.coloredString(earlyExecutionTimeString, 'blue')}`
|
2018-07-17 21:12:12 +00:00
|
|
|
);
|
|
|
|
done.resolve(earlyExecutionTime);
|
|
|
|
return done.promise;
|
|
|
|
};
|