Last active
August 7, 2020 17:18
-
-
Save zhoufenfens/b335fcfadff9d628103262d6fa1dd48a to your computer and use it in GitHub Desktop.
尽快输出
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const asyncFun = (i, cb) => { | |
setTimeout(() => { | |
let result = 2 * i | |
cb(result) | |
}, Math.random() * 1000); | |
} | |
const results = [] | |
var rIndex = 1 | |
const handle = (result, i) => { | |
results[i] = result | |
while (results[rIndex]) { // (results[rIndex]) 不能有0正常值 | |
console.log(rIndex + "," + results[rIndex++]); | |
} | |
} | |
var total = 20; | |
for (let i = 1; i < total; i++) { | |
((j) => { | |
asyncFun(j, (result) => { | |
handle(result, j) | |
}) | |
})(i) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment