question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

deasync hangs in an asynchronous context

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:8
  • Comments:18 (3 by maintainers)

github_iconTop GitHub Comments

11reactions
leo60228commented, Jan 24, 2019

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:

Is there any way to work around this bug?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/abbr/deasync/issues/21#issuecomment-457180359, or mute the thread https://github.com/notifications/unsubscribe-auth/AH996cZP3D8NQJAhCQK0wR_E4gyPdNIsks5vGaeLgaJpZM4FT0W0 .

1reaction
lmcsucommented, May 16, 2022

Wrapping the code into process.nextTick somehow helped me though, I don’t know if this is related

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found