yield断点的使用

function* demo(stock){
    while(true){
      yield Math.random()*10; //获取最近价格
      }
}
var demoa  = demo("IBM");
let limitPrice = 1; //想要的价格
let price = 100; //当前价格
while(price > limitPrice){
    price =  demoa.next().value;
  console.log(`${price}`);
}
console.log(`${price}`); //最后想要的价格


// function* demo(){
// console.log(1111);
//   yield;
//   console.log(2222);
// }
// let demoa = demo();
// demoa.next();
// demoa.next();

 

posted @ 2018-03-23 21:44  大智如蠢  阅读(119)  评论(0)    收藏  举报