Salve a tutti!

Ho un problema con Gulp. In pratica ho due funzioni, la prima fa il Dump di un database, la secondo lo elimina. Mi serve fare il dump semplicemente perchè se erronamente una persona elimina il database questo per sicurezza prima viene backuppato...

Ho due funzioni per questo:
codice:
// Dump the database, just to avoid accidental use of this task
function dumpDB ( ) {

  var conn = mysql.createConnection({
    host     : config.db.dbHost,
    user     : config.db.dbUser,
    password : config.db.dbPassword,
  });

  conn.connect();

  // Check if is there are tables in the database to backup.

  return conn.query('SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = \'' + config.db.dbName + '\'', function (error, results, fields) {
    if (error) throw error;

    conn.end();
    count = results[0]['COUNT(*)'];
    
    if(count>0){

      // create trash folder if it doesn't exists
      if(! fs.existsSync(config.paths.trash)){
        fs.mkdirSync(config.paths.trash);
      }else{
        del.sync(config.paths.trash + '**/*');
      }

      // dump the result straight to a file
      mysqldump({
        connection: {
          host     : config.db.dbHost,
          user     : config.db.dbUser,
          password : config.db.dbPassword,
          database : config.db.dbName,
        },
        dumpToFile: config.paths.trash + 'dump_' + new Date().toISOString().slice(0,19).replace(/:/g, "-").replace("T", "@") + '.sql',
      });      
    }else{

      f.alert('Database <' + config.db.dbName + '> doesn\'t contain anything.\n# Nothing will be dumped.')

    }

  });

}

function deleteDB (done) {

  var pool = mysql.createPool({
    host     : config.db.dbHost,
    user     : config.db.dbUser,
    password : config.db.dbPassword
  });

  return pool.getConnection(function(err, connection) {

    if (err) throw err; // not connected!

    // Use the connection
    connection.query('SHOW DATABASES LIKE \'' + config.db.dbName + '\'', function (error, results, fields) {

      // When done with the connection, release it.
      connection.release();

      if (error) throw error;

      if(results.length>0){
        
        // Use the connection
        connection.query('DROP DATABASE `' + config.db.dbName + '`', function (error, results, fields) {
      
          if (error) throw error;
      
          f.alert('Database <' + config.db.dbName + '> successfully deleted.');

        });

      }else{

        f.alert('Database <' + config.db.dbName + '> doesn\'t exists.');

      } // end if(results.length==0){
      
      pool.end();

    }); // end connection.query('SHOW DATABASES

  }); // pool.getConnection

}
Come sicuramente si evincerà dal codice, sono completamente autodidatta e sicuramente avrò scritto qualche oscenità, ma lanciando le funzioni, il dump dà sempre errore perchè deleteDB viene lanciata quando ancora il dump è in esecuzione...

Per lanciare le due funzioni le ho esportate così:

codice:
exports.delete = series(dumpDB, deleteDB)
Come posso far lanciare deleteDB solo quando dumpDB ha finito il suo lavoro???

Ho provato con gulp-sequence ma mi dà lo stesso problema.

Ah! Ovviamente i task lanciati singolarmente funzionano e fanno il loro lavoro.

L'errore che ricevo quando le eseguo insieme è questo:

[14:58:14] Starting 'dumpDB'...
[14:58:14] Finished 'dumpDB' after 77 ms
[14:58:14] Starting 'deleteDB'...
##
# Database <progetto-test> successfully deleted.
##
(node:13740) UnhandledPromiseRejectionWarning: Error: Table 'progetto-test.mfxqd_aiowps_events' doesn't exist
at PromiseConnection.query (D:\xampp\www\wp-init-v2\node_modules\mysql2\promise.js:92:22)
at DB.<anonymous> (D:\xampp\www\wp-init-v2\node_modules\mysqldump\dist\cjs.js:704:46)
at Generator.next (<anonymous>)
at D:\xampp\www\wp-init-v2\node_modules\mysqldump\dist\cjs.js:43:71
at new Promise (<anonymous>)
at __awaiter (D:\xampp\www\wp-init-v2\node_modules\mysqldump\dist\cjs.js:39:12)
at DB.multiQuery (D:\xampp\www\wp-init-v2\node_modules\mysqldump\dist\cjs.js:699:16)
at D:\xampp\www\wp-init-v2\node_modules\mysqldump\dist\cjs.js:76:42
at Generator.next (<anonymous>)
at fulfilled (D:\xampp\www\wp-init-v2\node_modules\mysqldump\dist\cjs.js:40:58)
(node:13740) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:13740) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Anche se dice dumpDB finished fater 77ms, in realtà quello sta ancora creando il file .sql!