I have a function bcrypt_hash()
which is running very slow.
After the user has entered a password, the program flow should continue while the BCrypt algorithm is running.
I have following code:
<script>
async function bcrypt_hash_async(s,rounds) {
return new Promise(resolve => {
resolve(bcrypt_hash(s,rounds));
});
}
function test() {
console.log("start calculation");
bcrypt_hash_async("hello world", 15).then(hash => console.log(hash));
console.log("continue program flow");
}
</script>
<input type="button" onclick="test()" value="Click me">
The JavaScript console shows the entries in the correct order:
start calculation
continue program flow
$2a$15$S1rOxr0THykuIOxqdehUh.gKDYIXpabfzRNyZ8y5FX.pu9..qEn4e
But actually, between "start calculation" and "continue program flow", the UI freezes until the calculation is done. How can I prevent that?
I am confused that the program hangs, although I have called the async function bcrypt_hash_async()
without await
.