Need some help with await

Hi. I could use some help with await or the like. I have a simple script here:

https://runkit.com/s4l4x/translate-text-to-many-languages

And I’d like to be able to list the ‘lang’ with the translation, but since the calls are asynchronous I’m always getting the last language in the list. If you have a sec I could use some help. Thanks!

Hi, sorry for the late response. I’ve coded up an answer here: https://runkit.com/tolmasky/answer-for-676-translate-text-to-many-languages

To use await, you need to first convert the function to a promise-style function. Usually, this is as easy as doing require("util").promisify(translator). Unfortunately, this particular library did not use the standard callback-style for functions, so we had to do it manually on line 3. Let me know if you need any more help or explanation.

Thanks!

Francisco

1 Like

This is awesome! Thanks Francisco!