Message from JavaScript discussions

April 2019

— 1) async processes (the correct choice)
2) threads (worker threads in node, web workers in browser)

— 

let time = null;
const func = null;
class Game {
constructor(pace, money){
this.hour = (a) =>{
a = Math.floor(this.startTime/60)
return (a > 23) ?a = 0 :a
};
this.minute = (a) => {
a = this.startTime%60
return (a < 10) ?'0'+a :a }
this.startTime = 464;
this.pace = pace;
this.money = money; //12
this.interval = null;
this.process = null;
}
displayTime(){
return this.hour() +':'+this.minute()
}
tick(){
return this.startTime++
}
play(...func){

const queue = (...func)=>{
for(let f of func){
return f()
}
}

this.interval = setInterval(()=>{
console.log(this.displayTime());
queue(...func)
this.tick()
console.log(time);
time++;}, 1000)
}
pause(){
return clearInterval(this.interval)
}
}
const newGame = new Game(1000, 10000);
time = newGame.startTime
const test =()=>newGame.pause()
setTimeout(test, 10000)

const test2 = () => console.log('walking')

const manage = (action, duration) => {
newGame.pause()
newGame.play(action)
const resume = () => {
newGame.pause()
newGame.play()
}
setTimeout(resume, duration)
}
newGame.play()

const testing = () => manage(test2, 4000)
setTimeout(testing, 3000)


This is the code that works with one process at the moment

— Let me try running it

— TRGWII do you see room for improvement?

— I never worked with neither of them

— Lots

— 7:44
464
7:45
465
7:46
walking
466
7:47
walking
467
7:48
walking
468
7:49
469
7:50
470

— I'm getting this

— Thanks, just don't give me a copy paste answer

— That is correct

— Walking is tested to run for a limited time

— And the rest is a timeline