deasync hangs in an asynchronous context
See original GitHub issueWhen using a deasynced function in asynchronous code, deasync hangs and never returns.
var deasync = require('deasync');
function async(cb) {
setTimeout(function() {
cb(null, 'value');
}, 0);
}
function sync() {
return deasync(async)();
}
console.log('start', sync());
async(function(err, val) {
console.log('async result', val);
console.log(sync());
console.log('done');
});
Notice that when run, the second call to sync
hangs. I was originally using promises when testing this and derived the previous code from this:
var Promise = require('q');
var deasync = require('deasync');
function async() {
return Promise.resolve('value');
}
function sync() {
var result, done;
async().then(function(response) {
result = response;
}).finally(function() {
done = true;
});
deasync.loopWhile(function() { return !done; });
return result;
}
console.log('start', sync());
async().then(function(result) {
console.log('async result', result);
return sync();
}).then(function(value) {
console.log(value);
console.log('done');
});
I also tried the above example using the Bluebird promise library and ended up with the same results. In the promise example, adding a console.log
inside the loopWhile
handler shows that it is stuck checking done
since the promise chain never completes.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:8
- Comments:18 (3 by maintainers)
Top Results From Across the Web
Developers - deasync hangs in an asynchronous context -
When using a deasynced function in asynchronous code, deasync hangs and never returns. var deasync = require('deasync'); function async(cb) ...
Read more >5 Reasons to Avoid Deasync for Node.js
This is exactly what happened in 2015, when a user reported that using deasync caused their app to hang in an asynchronous context....
Read more >Async vs Deasync in reality - node.js
I checked its issue list. There are some known serious issue, e.g. hanging in some extream cases. The question. Can the coming new...
Read more >Async/Await - Best Practices in Asynchronous Programming
Async all the way, Don't mix blocking and async code, Console main method. Configure context, Use ConfigureAwait(false) when you can, Methods that require ......
Read more >Swift 5.5: Replacing GCD With Async/Await
The mere word sends shivers up one's spine. And if it doesn't, it should. Main thread and background threads. Code that runs asynchronously....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’d say this package isn’t really necessary more, now that async functions exist.
On Thu, Jan 24, 2019, 7:31 AM Jam Risser notifications@github.com wrote:
Wrapping the code into
process.nextTick
somehow helped me though, I don’t know if this is related