异步编程-订单模式
//0:在排队 1:处理中 2 订单完成 3 订单取消 4 超时处理 const ShopOrderMap={} class Order { constructor(name){ this.name=name||'test'; if(!ShopOrderMap[name]){ ShopOrderMap[name]={ bit:[], curN:0, orderMap:{}//待处理的订单 }; } this.shopOrder=ShopOrderMap[this.name]; //新增加一个订单 this.myN=this.shopOrder.bit.length; this.shopOrder.bit[this.myN]='0'; this.shopOrder.orderMap[this.myN]=this; } //排队 wait(overTime){ return new Promise((res)=> { this.res=res; //没有人排队,处理当前订单 this.resolve() }) if(overTime){ this.timeInter=setTimeout(()=>{ this.reject() },overTime) } } //排队处理订单 resolve(){ if(this.myN===this.shopOrder.curN){ if(this