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,fn}) => {
const end = time - beginTime >= duration;
if(end) {
fn()
}
else return true
})
this.data.length && requestAnimationFrame(this.loop.bind(this))
}
}
let responses = `{duration : 10500, fn : ()=> console.log('test1')},
{duration : 14500, fn : ()=> console.log('test3')},
{duration : 15000, fn : ()=> console.log('test')}`
responses = eval(`[${responses}]`)
new Timer(responses)