UNPKG

@joergmittaglawo/dmvconfig

Version:

DMV Configuration scripts for Lawo V__matrix Distributed Multiviewers.

1 lines 1.86 kB
Object.defineProperty(exports,"__esModule",{value:!0}),exports.WorkQueue=exports.path_index=exports.snake_case=exports.path_strip_trailing_index=exports.path_to_branch=exports.path_tl=exports.path_hd=exports.IDPool=exports.pause_ms=exports.pause=void 0,exports.pause=function(t){return new Promise((n,s)=>{setTimeout(()=>{n()},1e3*t)})},exports.pause_ms=function(t){return new Promise((n,s)=>{setTimeout(()=>{n()},t)})};exports.IDPool=class{constructor(){this.cur_id=BigInt(0)}get_id(){return this.cur_id=this.cur_id+BigInt(1),this.cur_id.toString(36)}},exports.path_hd=function(t){const n=t.lastIndexOf(".");return-1!==n?t.substring(0,n):t},exports.path_tl=function(t){const n=t.lastIndexOf(".");return-1!==n?t.substring(n+1):t},exports.path_to_branch=function(t){return t.replace(/\[[0-9]+\]/g,"")},exports.path_strip_trailing_index=function(t){return t.replace(/\[[0-9]+\]$/,"")},exports.snake_case=function(t){let n="";for(const s of t){const t=s.toLowerCase();s!==t&&0!==n.length&&(n+="_"),n+=t}return n},exports.path_index=function(t){if("]"!==t.charAt(t.length-1))return;const n=t.lastIndexOf("[");return-1!==n?parseInt(t.substr(n+1,t.length-n-2)):void 0};exports.WorkQueue=class{constructor(t){this.num_running=0,this.todo=[],this.finalizers=[],this.num_workers=t.num_workers}get size(){return this.todo.length+this.num_running}get stats(){return{waiting:this.todo.length,running:this.num_running}}tick(){const t=Math.min(this.num_workers-this.num_running,this.todo.length),n=this.todo.splice(0,t);this.num_running+=t;for(const t of n)t().finally(()=>{this.num_running-=1,this.tick()});if(this.idle()){for(const t of this.finalizers)t();this.finalizers=[]}}idle(){return 0===this.num_running&&0===this.todo.length}push(t){this.todo.push(t),this.tick()}clear(){this.todo=[],this.tick()}drain(){return new Promise(t=>{this.finalizers.push(t),this.tick()})}};