Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async/await #50

Open
nine-2-five opened this issue Apr 20, 2017 · 2 comments
Open

async/await #50

nine-2-five opened this issue Apr 20, 2017 · 2 comments

Comments

@nine-2-five
Copy link

Is this library compatible with async/await?

I tried this:

var result = await ftps.mirror({
        remoteDir: remote_path, // + '/.',
        localDir: commit_dir + '/' + commit_diffs.commit + '/.',
        //parallel: true,
        upload: true,
        //filter: '/.**/',
    }).exec()

and got this:
Error: Callback is missing to exec() function.

@cjnqt
Copy link

cjnqt commented May 16, 2017

async/await works with functions that returns a Promise. So to make this work, you gotta make ftps.mirror().exec() return a promise.

@SkullMasher
Copy link

SkullMasher commented Mar 21, 2023

async/await works with functions that returns a Promise. So to make this work, you gotta make ftps.mirror().exec() return a promise.

Just in case people wants the gist of making this module works with async/await here's what I did. Sorry for necroposting.

const mirrorFTP = new Promise((resolve, reject) => {
  return ftps.mirror({
    remoteDir: remote_path, // + '/.',
    localDir: commit_dir + '/' + commit_diffs.commit + '/.',
    //parallel: true,
    upload: true,
    //filter: '/.**/',
  }).exec((err, res) => {
    if (res.error) { reject(`❌ FTP sync error: ${res.error}`) }
    resolve(`✔️ FTP Mirroring done`)
  })
})

try {
  const result = await mirrorFTP
  console.log(result)
} catch (e) {
  console.error(e)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants