“Callback Hell” Kode Jawaban

Callback Hell

fs.readdir(source, function (err, files) {
  if (err) {
    console.log('Error finding files: ' + err)
  } else {
    files.forEach(function (filename, fileIndex) {
      console.log(filename)
      gm(source + filename).size(function (err, values) {
        if (err) {
          console.log('Error identifying file size: ' + err)
        } else {
          console.log(filename + ' : ' + values)
          aspect = (values.width / values.height)
          widths.forEach(function (width, widthIndex) {
            height = Math.round(width / aspect)
            console.log('resizing ' + filename + 'to ' + height + 'x' + height)
            this.resize(width, height).write(dest + 'w' + width + '_' + filename, function(err) {
              if (err) console.log('Error writing file: ' + err)
            })
          }.bind(this))
        }
      })
    })
  }
})
Abror

Callback Hell

let order = (call_production) => {
  setTimeout(() => {    
    call_production();
  }, 1000);
};
let production = () => {
  setTimeout(() => {
    console.log("step 1");
    setTimeout(() => {
      console.log("step 2");
      setTimeout(() => {
        console.log("step 3");
        setTimeout(() => {
          console.log("step 4");
          setTimeout(() => {
            console.log("step 5");
            setTimeout(() => {
              console.log("step 6");
              setTimeout(() => {
                console.log("step 7");
                setTimeout(() => {
                  console.log("step 8");
                  setTimeout(() => {
                    console.log("step 9");
                    setTimeout(() => {
                      console.log("step 10");
                      setTimeout(() => {
                        console.log("A call backhell");
                      }, 1000);
                    }, 1000);
                  }, 1000);
                }, 1000);
              }, 1000);
            }, 1000);
          }, 1000);
        }, 1000);
      }, 1000);
    }, 1000);
  }, 1000);
};
order(production);
polyglot orca

Jawaban yang mirip dengan “Callback Hell”

Pertanyaan yang mirip dengan “Callback Hell”

Lebih banyak jawaban terkait untuk “Callback Hell” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya