-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfiguration.js
More file actions
44 lines (30 loc) · 1.42 KB
/
configuration.js
File metadata and controls
44 lines (30 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import Signal from 'signal';
class Configuration {
simulation; // true/false
rate;
flowDuration;
computationDuration;
constructor(){
this.paused = new Signal(); // time does not pass
this.simulation = new Signal( true ); // true=gui-mode, false=server-mode
// ability to stop, slow, and speed up the running program
this.rate = new Signal( .5 ); // 0 to stop program! 1=normal-operation
// These are for simulations of computations and packets flowing over a wire
this.computationDurationMs = new Signal( 111); // ms
this.flowDurationMs = new Signal( 555 ); // ms
this.computationDuration = new Signal( this.computationDurationMs.value / this.rate.value );
this.flowDuration = new Signal( this.flowDurationMs.value / this.rate.value );
// my signals can have dependencies
const simulationCalculation = new Signal(1);
simulationCalculation.addDependency(this.rate);
simulationCalculation.addDependency(this.computationDurationMs);
simulationCalculation.addDependency(this.flowDurationMs);
simulationCalculation.subscribe((_,rate, computationDurationMs, flowDurationMs)=>{
this.computationDuration.value = computationDurationMs / rate;
if(rate<=0.05) rate = 0.05;
this.flowDuration.value = flowDurationMs / (rate * rate);
if(rate===1) this.flowDuration.value = 0; // LUDICROUS SPEED!
});
} // constructor
};
export default new Configuration();