Wednesday, 15 March 2017

Node.js: Asynchronous Callback Execution. Is this Zalgo?

Executing the below using node - 6.0.

function A(callback) {
  console.log('A');
  callback();
}

function B() {
  console.log('B')
}

function C() {
  console.log('C');
}

A(C);
B();


// Result is A,C,B i expected that A, B, C

But changing the above example to use process.nextTick() prints A, B, C

function A(callback) {
  console.log('A');
  process.nextTick(() => {
    callback();
  });
}

function B() {
  console.log('B')
}

function C() {
  console.log('C');
}

A(C);
B();

Is this what we call as zalgo ? Can anyone provide me a realtime example of this, which will cause major breakdown ?



via Sathish

No comments:

Post a Comment