forked from vkurchatkin/deasync
-
-
Couldn't load subscription status.
- Fork 75
Open
Labels
Description
When 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.
dy, zamnuts, sentialx, emiliavanderwerf, DuyguA and 4 more