dima85,
class Timer {
constructor(data) {
this.data = data.map(obj => ({...obj,beginTime : performance.now()}));
requestAnimationFrame(this.loop.bind(this));
}
loop(time){
this.data = this.data.filter(({beginTime,duration,"console" : txt}) => {
const end = time - beginTime >= duration;
if(end) {
console.log(txt)
}
else return true
})
this.data.length && requestAnimationFrame(this.loop.bind(this))
}
}
let responses =
[{"duration" : 10500, "console":"test1"},
{"duration" : 14500, "console":"test3"},
{"duration" : 15000, "console":"test"}]
new Timer(responses)