Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

109
Views
Usar Promesa y esperar en lugar de luego ()

Estoy usando MusicKit-JS y aunque este código funciona, no sé si hay otra forma de escribirlo.

Todos los métodos de música devuelven __awaiter(...) .

¿Hay alguna manera de escribir esto usando promesas? No sé mucho sobre ellos, así que no pude hacerlo funcionar usando promesas.

 music.stop() .then(function () { music.setQueue({}) .then(function () { music.setQueue({ song: id }) .then(function () { music.play() }) }) });
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Suponiendo que todas estas funciones son promesas de devolución, puede envolverlas en una función async y luego usar await y luego deshacerse del anidamiento profundo:

 async function run() { await music.stop(); await music.setQueue({}); await music.setQueue({song: id}); await music.play(); } run().then(() => { console.log("done"); }).catch(err => { console.log(err); });
about 4 years ago · Juan Pablo Isaza Report

0

Todo lo que necesita hacer es declarar sus funciones asíncronas. Entonces podrás usar await

 async function() { await music.stop(); // .then(function () { await music.setQueue({}) // .then(function () { await music.setQueue({ song: id }) // .then(function () { music.play() }) }) });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!