February 2019
Beginner
694 pages
18h 4m
English
By way of a comparison of the two techniques we have discussed, let's take a look at a simplified version of the callback versus the promise syntax, as follows:
Our standard callback mechanism is as follows:
function standardCallback() {
function afterCallbackSuccess() {
// execute this code
}
function afterCallbackError() {
// execute on error
}
// invoke async function
invokeAsync(afterCallbackSuccess, afterCallbackError);
}
And our promise syntax is as follows:
function usingPromises() {
delayedPromise().then(
() => {
// execute on success
}
).catch (
() => {
// execute on error
}
);
}
As we can see, using promises introduces a fluent syntax for handling asynchronous programming.
Read now
Unlock full access