Promises in JS allow you to do async programming, as follows:
DoSomething().then(success, failure);
DoSomethingElse();
whenever i write th
Yes, JavaScript is single-threaded, which means you should never block this single thread. Any long-running, waiting operation (typically AJAX calls or sleeps/pauses) are implemented using callbacks.
Without looking at the implementation here is what happens:
DoSomething
is called and it receives success
and failure
functions as arguments.
It does what it needs to do (probably initiating long-running AJAX call) and returns
DoSomethingElse()
is called
...
Some time later AJAX response arrives. It calls previously defined success
and failure
function