Last active
May 19, 2020 11:28
-
-
Save jj11hh/d2234f20d6e570442ce702e257ca9357 to your computer and use it in GitHub Desktop.
convert decimal numbers to hexadecimal asynchoronously
This file contains hidden or 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
| function xxx_rpc_call(x, callback){ | |
| setTimeout(callback, 1000 + Math.random()*1000, x.toString(16)); | |
| } | |
| const results = new Array(); | |
| let index = 1; | |
| function cb_arrange(x){ | |
| return (result) => { | |
| results[x] = result; | |
| if (x == 1 || results[x - 1] !== undefined){ | |
| if (x === index){ | |
| while (results[index] !== undefined){ | |
| console.log(`${index} -> ${results[index]}`); | |
| index++; | |
| } | |
| } | |
| } | |
| }; | |
| } | |
| for (let i = 1; i <= 30; i ++){ | |
| xxx_rpc_call(i, cb_arrange(i)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment