node-udev icon indicating copy to clipboard operation
node-udev copied to clipboard

Promises don't work in the monitor callback!

Open nbroeking opened this issue 8 years ago • 2 comments

const udev = require('udev'); const monitor = udev.monitor();

monitor.on('add', () => {
  console.log('1');
  Promise.resolve()
  .then(() => {
    console.log('2');
  })
  .then(() => {
    console.log('3');
  });
});

Output should be:

1 2 3

Output is

1

However if you do

monitor.on('add', () => {
  console.log('1');
  setTimeout(() => {
    Promise.resolve()
    .then(() => {
      console.log('2');
    })
    .then(() => {
      console.log('3');
    });
  })
});

Then the output is

1 2 3

nbroeking avatar Jun 27 '17 19:06 nbroeking

@KevinDyer

nbroeking avatar Jun 27 '17 19:06 nbroeking

If the Promise.resolve() works outside, then the culprit is likely in the function on_handle_event at udev.cc:51.

cheery avatar Jun 27 '17 19:06 cheery