Skip to content

Promises don't work in the monitor callback! #24

@nbroeking

Description

@nbroeking

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions