JS Bin
// source https://jsbin.com/mibeqeb
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
'use strict';
var firstAPI = function firstAPI(callback) {
console.log('Called FirstAPI');
//Heavy processing in server
setTimeout(function () {
callback('FirstAPI Result');
}, 3000);
};
var secondAPI = function secondAPI(input, callback) {
console.log('Called SecondAPI');
//Heavy processing in server
setTimeout(function () {
callback('SecondAPI Result ' + input);
}, 2000);
};
firstAPI(function (res1) {
console.log('Got result 1 => ' + res1);
secondAPI(res1, function (res2) {
console.log('Got result 2 => ' + res2);
});
});
</script>
<script id="jsbin-source-javascript" type="text/javascript">const firstAPI = (callback) => {
console.log('Called FirstAPI');
//Heavy processing in server
setTimeout(() => {
callback('FirstAPI Result');
}, 3000);
}
const secondAPI = (input, callback) => {
console.log('Called SecondAPI');
//Heavy processing in server
setTimeout(() => {
callback('SecondAPI Result '+input);
}, 2000);
}
firstAPI((res1) => {
console.log('Got result 1 => '+res1);
secondAPI(res1, (res2) => {
console.log('Got result 2 => '+res2);
});
});
</script></body>
</html>
'use strict';
var firstAPI = function firstAPI(callback) {
console.log('Called FirstAPI');
//Heavy processing in server
setTimeout(function () {
callback('FirstAPI Result');
}, 3000);
};
var secondAPI = function secondAPI(input, callback) {
console.log('Called SecondAPI');
//Heavy processing in server
setTimeout(function () {
callback('SecondAPI Result ' + input);
}, 2000);
};
firstAPI(function (res1) {
console.log('Got result 1 => ' + res1);
secondAPI(res1, function (res2) {
console.log('Got result 2 => ' + res2);
});
});