mongodb-backup icon indicating copy to clipboard operation
mongodb-backup copied to clipboard

Why nest promises instead of use return value?

Open aj0strow opened this issue 9 years ago • 0 comments

It seems messy to do this:

tasks.mongodump().then(function () {
    tasks.zip(config.database, path.join(__dirname, 'dump')).then(function (filepath) {
      tasks.s3(filepath).then(function () {
        tasks.clean(filepath).then(tasks.clean(path.join(__dirname, 'dump', config.database))).then(function () {
          utils.log('debug', 'Done.');
        }).catch(function (ex) {
          utils.log('error', ex);
        });
      }).catch(function (ex) {
        utils.log('error', ex);
      });
    });
  });

When you can do this:

 tasks.mongodump().then(function () {
    return tasks.zip(config.database, path.join(__dirname, 'dump'))
  }).then(function (filepath) {
    return tasks.s3(filepath)
  }).then(function () {
    return tasks.clean(filepath)
  }).then(function () {
    return tasks.clean(path.join(__dirname, 'dump', config.database))
  }).then(function () {
    utils.log('debug', 'Done.');
  }).catch(function (ex) {
    utils.log('error', ex);
  })

aj0strow avatar Jul 13 '15 13:07 aj0strow