当前位置:网站首页>#19生成器函数经典案例
#19生成器函数经典案例
2022-06-23 17:59:00 【sanda_nd】
1、1s后输出111,2s后输出222,3秒后输出333
// 像这种不断的回调会产生回调地狱
setTimeout(() => {
console.log(111)
setTimeout(() => {
console.log(222)
setTimeout(() => {
console.log(333)
}, 3000)
}, 2000)
}, 1000)
function one() {
setTimeout(() => {
console.log(111)
iterator.next()
}, 1000)
}
function two() {
setTimeout(() => {
console.log(222)
iterator.next()
}, 2000)
}
function three() {
setTimeout(() => {
console.log(333)
iterator.next()
}, 3000)
}
function* gen() {
yield one()
yield two()
yield three()
}
let iterator = gen()
iterator.next() // 直接调用三次,没有延时的效果2、 模拟获取用户数据、订单数据、商品数据


边栏推荐
- [noi 2014] 15. Syndrome de difficulté à se lever [binaire]
- Task management of embedded development foundation (thread management)
- Ges graph computing engine hyg unveils the secrets of Graph Segmentation
- 从零开发小程序和公众号【第一期】
- Product design - Requirements Analysis
- VirtP4笔记
- Jerry's adding timer interrupt [chapter]
- Revelation: Bezos' business logic and leadership rules
- 可编程数据平面(论文阅读)
- 矩阵分析笔记(二)
猜你喜欢

Description of all shortcut keys in win11 system

嵌入式开发基础之任务管理(线程管理)

用软件可编程FPGA加速网络边缘的移动应用总结

Leetcode question brushing: hash table 03 (happy number)

IOT platform construction equipment, with source code

Graffiti intelligence passed the hearing: Tencent is an important shareholder planning to return to Hong Kong for listing

【Qt】第十章:数据库

Nanxin semiconductor rushes to the scientific innovation board: its annual revenue is RMB 980 million. Sequoia Xiaomi oppo is the shareholder

js25题目

How can enterprises do business monitoring well?
随机推荐
Rancher2.6 new monitoring QuickStart
【NOI2014】15. Difficult to get up syndrome [binary]
Leetcode: hash table 02 (intersection of two arrays)
Operation of simulated test platform for elevator driver test questions in 2022
高级计网笔记(九)
[binary tree] flip the binary tree to match the preorder traversal
韬略生物冲刺科创板:年亏损过亿 实控人张大为夫妇为美国籍
Why create a public OKR?
Product feedback mechanism
Jerry's SD card will reset after he enters soft off [chapter]
杰理之串口设置好以后打印乱码,内部晶振没有校准【篇】
盘点四种WiFi加密标准:WEP、WPA、WPA2、WPA3
机器学习工作岗位
矩阵分析笔记(二)
盛科通信IPO过会:年营收4.6亿 中国振华与产业基金是股东
Jerry's broadcast MP3 prompt sound function [chapter]
Jerry added an input capture channel [chapter]
[QT] multiple choice questions
产品设计- 需求分析
Sany Heavy energy technology innovation board listed: annual revenue of RMB 10.2 billion and market value of RMB 47 billion