zhangjianfang19910327 / zjianfang

node web
MIT License
1 stars 0 forks source link

chan demo #1

Open zhangjianfang19910327 opened 5 years ago

zhangjianfang19910327 commented 5 years ago

const chan=require('chan'); var co = require('co'); const ch=chan(); async function parts(fn) { return new Promise(function (resolve, reject) { ch(function (err, res) { if (err) return reject(err) resolve(res);

  })
})

} let count=0;

setInterval(()=>{ count++; ch(count); },4000); let part; async function fun(){ while( (part= await( new Promise( async function(res,rej){ let result= await parts(); res(result); } ) ) )!=null ) { console.log(part); } } fun();