showing results for - "nested callbacks javascript"
Kevin
29 Apr 2016
1//nested callback eg, with conditional check for url
2
3function download3(urls, success, fail) {
4            setTimeout(() => {
5                console.log(`Downloading ${urls} ...`);
6                var err = urls.length === 0 || !urls;
7                err ? fail(urls) : success(urls);
8            }, 3000);
9        }
10
11        const url_a = 'https://www.javascripttutorial.net/pic1.jpg';
12        const url_b = 'https://www.javascripttutorial.net/pic2.jpg';
13        const url_c = '';
14
15        download3(url_a, function(picture_a) {
16            console.log(`Processing ${picture_a}`);
17
18              download3(url_b, function(picture_b) {
19                  console.log(`Processing ${picture_b}`);
20
21                    download3(url_c, function(picture_c) {
22                        console.log(`Processing ${picture_c}`);
23                    }, function(picture_a){
24                        console.log(`Handling error...`)});
25
26              },function(picture_b){
27                      console.log(`Handling error...`)});
28
29        },function(picture_c){
30                    console.log(`Handling error...`)});