Open zhangjianfang19910327 opened 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();
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();