-
-
Notifications
You must be signed in to change notification settings - Fork 73
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
Embedded Promise not Resolving #140
Comments
I'm having the same problem, is there any way to solve this or is there a fix already? |
Same issue. I have to call synchronous code inside a handler for a webserver which is asynchronous. The synchronous part needs to call an external service where the client library is async-only. I tried using deasync on that client library, and ran into this issue. |
+1 |
1 similar comment
+1 |
Avoid this library if there is any good chance to do so. Or if you are not 100% sure how it works. Otherwise, you can easily get your code in deadlock. |
try this const deasync = require('deasync');
deasync.promise = function(fn) {
return function () {
var done = false
var args = Array.prototype.slice.apply(arguments)
var err
var res
fn.apply(this, args).then(resolve).catch(reject);
deasync.loopWhile(function () {
return !done
})
if (err)
throw err
return res
function resolve(r) {
res = r
done = true
}
function reject(e) {
err = e
done = true
}
}
};
const readFilePromiseSync = deasync.promise(require('fs').promises.readFile);
const buffer = readFilePromiseSync(__filename);
console.log({buffer}); |
I've been building a CLI tool and have needed to make use an
async
library within synchronous functions. I've encountered an issue wheredeasync
will lock up when the result is dependent on a Promise resolving. It works fine with Node 10, but not with 12 or 14. I've managed to come up with this minimal reproducing code:I originally discovered this using https://github.com/Yukaii/synchronized-promise/blob/master/lib/index.js, which has some timeout logic. When using that the output is:
Possibly duplicate of #136 and/or #138.
The text was updated successfully, but these errors were encountered: