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