Created
December 5, 2016 15:08
-
-
Save dmitrykuznetsovdev/aaf7510e8db70cc88b9238a7b561f7be to your computer and use it in GitHub Desktop.
callstack block
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
/** | |
* поставит в очередь Callback Queue стразу | |
*/ | |
setTimeout(() => { | |
console.log('setTimeout', 1); | |
}, 0) | |
setTimeout(() => { | |
console.log('setTimeout', 2); | |
}, 0) | |
setTimeout(() => { | |
console.log('setTimeout', 3); | |
}, 0) | |
setTimeout(() => { | |
console.log('setTimeout', 4); | |
}, 0) | |
/** | |
* поставит в очередь Callback Queue только через 500 mc | |
*/ | |
setTimeout(() => { | |
console.log('setTimeout', 5); | |
}, 500) | |
setTimeout(() => { | |
console.log('setTimeout', 6); | |
}, 500) | |
setTimeout(() => { | |
console.log('setTimeout', 7); | |
}, 500) | |
setTimeout(() => { | |
console.log('setTimeout', 8); | |
}, 500) | |
setTimeout(() => { | |
console.log('setTimeout', 9); | |
}, 500) | |
setTimeout(() => { | |
console.log('setTimeout', 10); | |
}, 500) | |
function asyncLoop(arr, cb){ | |
arr.forEach((index)=>{ | |
setTimeout(cb.bind(null, index), 0); | |
}) | |
} | |
/** | |
* заблокирует весь call stack | |
* поставит в очередь обработчики | |
* | |
* после их выполнения, запустит те что поставились через 500 mc | |
*/ | |
asyncLoop([1, 2, 3, 4], (index)=>{ | |
for (let i = 0; i < 3000000000; i++) { | |
} | |
console.log(index, "index"); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment