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

Here's how you can use this with async / await #56

Open
nlspnsgen opened this issue Aug 14, 2021 · 2 comments
Open

Here's how you can use this with async / await #56

nlspnsgen opened this issue Aug 14, 2021 · 2 comments

Comments

@nlspnsgen
Copy link

nlspnsgen commented Aug 14, 2021

Hi,
great project! Just leaving this here in case someone else wants to rewrite the example code with async / await.

const { promisify } = require('util');

const slsk = require('slsk-client');
const connect = promisify(slsk.connect);

const main = async () => {
  try {
    const client = await connect({
      user: 'your_username',
      pass: 'your_password'
    });
    const search = promisify(client.search);
    const download = promisify(client.download);
    console.log("searching...");
    const searchResults = await search.call(client, ({ req: 'random', timeout: 2000 }));
    console.log("search done!")
    console.log("downloading: ", searchResults[0]);
    await download({ file: searchResults[0], path: __dirname + '/random.mp3'});
    console.log("download done!");
  } catch (err) {
    console.log(err);
  }
}

main();
@B1zguy
Copy link

B1zguy commented May 25, 2022

Oh my gosh, thank you so much! I almost thought this couldn't be done.

@theaccessvirus
Copy link

tks for sharing

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