Вы можете использовать Array.prototype.map()
на MOVIES
и отображать каждое движение ie string
на ожидаемое Promise
, затем await
на Promise.all()
для продолжения после разрешения всех Promise
с и у тебя есть все свои торренты.
(async () => {
async function search() {
try {
// return value will be a Promise
return await TorrentSearchApi.search(`${movie} 1080`, 'Movies', 1);
} catch (e) {
console.error(e);
// we're not returning anything in case of an error, so the return value will be `undefined`
}
}
const TORRENTS = await Promise.all(
MOVIES
.map((movie) => search(movie))
.filter((torrentPromise) => torrentPromise !== undefined) // here we filter out all the searches that resulted in an error
);
})();