due
Due makes your callback behave well.
If you use to write asynchronous Node.js code, you might have encounter the Callback hell aka Pyramid of Doom.
To avoid this pattern, it is common to wrap callback into Promises, or one of the equivalent (Q, Async, Vow ...).
A promise is simply a different pattern allowing to write asynchronous sequence as a cascade of call, instead of a pyramide of call.
Promises are coming in ECMAScript 6. so it is time to switch, and start writing better code.
Due is very similar to promises, except for two things.
- The interface is slightly differnt. It doesn't expect two callbacks - one for success, one for rejection - like promises do, but only one. Exactly like th callback you are used to in node.js
- A due doesn't provide the two methods all and race that promises provide. That means you need to synchronize your execution the same way you were used to in node.js, using variables and conditinos. For the more nerdy of you, that makes due sound regardless to promises, but not complete.
However, you might already have tons of lines with callbacks. and you don't want to refactor everything.
Here we provide to you a due compiler
online compiler