js 實現紅綠燈變換


class LightFn{
    async run(){
        while(true){
            console.log('this is green 3000');
            await this.sleep(3000);
            console.log('this is yellow 1000');
            await this.sleep(1000);
            console.log('this is red 2000');
            await this.sleep(2000);            
        }    
    }
    sleep(duration){
        return new Promise((resolve, reject)=>{
            setTimeout(resolve ,duration);
        })
    }
}

let a = new LightFn();
a.run();

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM