Files
early/ts/index.ts

38 lines
1.0 KiB
TypeScript
Raw Normal View History

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