February 2019
Beginner
694 pages
18h 4m
English
A promise is an object that is created by passing in a function that accepts two callbacks. The first callback is used to indicate a successful response, and the second callback is used to indicate an error response. Consider the following function definition:
function fnDelayedPromise (
resolve: () => void,
reject : () => void)
{
function afterTimeout() {
resolve();
}
setTimeout( afterTimeout, 2000);
}
Here, we have defined a function named fnDelayedPromise that takes two functions as arguments. These functions are named resolve and reject, and they both return a void. Within the body of the fnDelayedPromise function, we are again calling setTimeout (on the last line of the function) to wait for 2 seconds before calling the ...
Read now
Unlock full access