1 Star 0 Fork 0

白一梓 / async-tutorial-code

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
sync.js 554 Bytes
一键复制 编辑 原始数据 按行查看 历史
白一梓 提交于 2015-05-14 17:39 . 增加对于node0.12.x的扩展支持
function synchronizedCode(tag, times) {
tag = tag || '';
times = times || 4;
var last = new Date().getTime();
var count = 0;
while (true) {
var now = new Date().getTime();
if (now - last > 1000 * 2) {
last = now;
count++;
if (tag) {
console.log('the %dth count in [%s].',count,tag);
} else {
console.log('the %dth count.',count);
}
}
if (count > times) {
if (tag) {
console.log('exist while in [%s].',tag);
} else {
console.log('exist while.');
}
break;
}
}
}
module.exports = synchronizedCode;
JavaScript
1
https://gitee.com/yunnysunny/async-tutorial-code.git
git@gitee.com:yunnysunny/async-tutorial-code.git
yunnysunny
async-tutorial-code
async-tutorial-code
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891