Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting infinite while loop using Promise, then #151

Open
aryanrajput opened this issue Sep 5, 2021 · 1 comment
Open

Getting infinite while loop using Promise, then #151

aryanrajput opened this issue Sep 5, 2021 · 1 comment

Comments

@aryanrajput
Copy link

aryanrajput commented Sep 5, 2021

var result = null;
var isDone = false;

const p = new Promise((resolve, reject) => {
setTimeout(function(){
console.log("This is set time out")
resolve('resolved')
}, 4000)
})

p.then(res =>{
result = res;
isDone = true;
console.log("This is then section.")
})

while(!isDone) {
console.log("in while", result)
deasync.sleep(10000);
}

console.log(data)

@anonghuser
Copy link

no need for any timers to get a reproduction, even just this simple code hangs:

import deasync from 'deasync'
const test = deasync(function(r, cb) {
    Promise.resolve().then(()=>cb(null, r))
})
console.log(1)
console.log(test(2))
console.log(3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants