nv-facutil-clock
Advanced tools
Comparing version 1.0.3 to 1.0.4
57
index.js
@@ -288,2 +288,8 @@ | ||
const { | ||
set_interval_without_rslts, | ||
_psj, | ||
} = require("nv-facutil-promise"); | ||
class Cron { | ||
@@ -318,7 +324,7 @@ #interval = null | ||
clear() { | ||
clearInterval(this.#interval); | ||
this.#interval(); | ||
this.#interval = null | ||
} | ||
launch() { | ||
this.#interval = setInterval( | ||
let {newClearInterval} = set_interval_without_rslts( | ||
()=> { | ||
@@ -331,6 +337,53 @@ let d = this.#auto.dict(); | ||
); | ||
this.#interval = newClearInterval; | ||
} | ||
} | ||
const now = ()=>(new Date()).getTime() | ||
class StopWatch { | ||
#start_at = undefined; | ||
#end_at = undefined; | ||
#psj = undefined; | ||
get start_at_() {return(this.#start_at)} | ||
get end_at_() {return(this.#end_at)} | ||
get passed_() { | ||
if(this.#end_at !== undefined) { | ||
return(this.#end_at - this.#start_at) | ||
} else if(this.#start_at !== undefined) { | ||
return(now() - this.#start_at) | ||
} else { | ||
} | ||
} | ||
clear() { | ||
this.#start_at = undefined | ||
this.#end_at = undefined | ||
this.#psj = undefined | ||
} | ||
start() { | ||
this.clear(); | ||
this.#psj = _psj(); | ||
this.#start_at = now(); | ||
return(this.#psj[0]) | ||
} | ||
stop() { | ||
this.#end_at = now(); | ||
let d = {start_at:this.#start_at,end_at:this.#end_at,costed:this.passed_} | ||
this.#psj[1](d); | ||
return(d) | ||
} | ||
get [Symbol.toStringTag]() { | ||
let d = `start_at:${this.#start_at} duration:${this.passed_} end_at:${this.#end_at}` | ||
return(d) | ||
} | ||
} | ||
module.exports = { | ||
now, | ||
//// | ||
StopWatch, | ||
stop_watch:new StopWatch(), | ||
//// | ||
ERROR_DICT, | ||
@@ -337,0 +390,0 @@ Auto, |
{ | ||
"name": "nv-facutil-clock", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "clock,date,generator,stream,cron", | ||
@@ -17,3 +17,6 @@ "main": "index.js", | ||
"author": "", | ||
"license": "ISC" | ||
"license": "ISC", | ||
"dependencies": { | ||
"nv-facutil-promise": "^1.0.27" | ||
} | ||
} |
@@ -180,3 +180,3 @@ nv-facutil-clock | ||
const {Cron} = require("./index") | ||
const {Cron} = require("nv-facutil-clock") | ||
var frequency =1000 | ||
@@ -213,2 +213,44 @@ function task_func(a,b,c) { | ||
stop watcher | ||
------------- | ||
> var stop_watch = new StopWatch() | ||
undefined | ||
> stop_watch | ||
StopWatch [start_at:undefined duration:undefined end_at:undefined] {} | ||
> | ||
> var p = stop_watch.start() | ||
undefined | ||
> p | ||
Promise { | ||
<pending>, | ||
[Symbol(async_id_symbol)]: 68, | ||
[Symbol(trigger_async_id_symbol)]: 5, | ||
[Symbol(destroyed)]: { destroyed: false } | ||
} | ||
> stop_watch | ||
StopWatch [start_at:1639454327229 duration:7695 end_at:undefined] {} | ||
> stop_watch | ||
StopWatch [start_at:1639454327229 duration:9265 end_at:undefined] {} | ||
> stop_watch | ||
StopWatch [start_at:1639454327229 duration:10850 end_at:undefined] {} | ||
> | ||
> stop_watch | ||
StopWatch [start_at:1639454327229 duration:13856 end_at:undefined] {} | ||
> stop_watch.stop() | ||
{ start_at: 1639454327229, end_at: 1639454350716, costed: 23487 } | ||
> | ||
> p | ||
Promise { | ||
{ start_at: 1639454327229, end_at: 1639454350716, costed: 23487 }, | ||
[Symbol(async_id_symbol)]: 68, | ||
[Symbol(trigger_async_id_symbol)]: 5, | ||
[Symbol(destroyed)]: { destroyed: false } | ||
} | ||
> stop_watch | ||
StopWatch [start_at:1639454327229 duration:23487 end_at:1639454350716] {} | ||
> | ||
METHODS | ||
@@ -215,0 +257,0 @@ ======= |
18387
379
286
1
+ Addednv-facutil-promise@^1.0.27
+ Addednanoid@3.3.7(transitive)
+ Addednv-array-basic@1.0.25(transitive)
+ Addednv-array-combo@1.0.0(transitive)
+ Addednv-facutil-basic@1.3.20(transitive)
+ Addednv-facutil-defp@1.0.3(transitive)
+ Addednv-facutil-notandor@1.0.5(transitive)
+ Addednv-facutil-promise@1.0.34(transitive)