1
Someone can help me, I’m with a function returning as pending, but do not know what can be already tried everything. follows my code:
const episodes = seasons.map((el) => {
const season = moviedb
.seasonInfo({ language: language, id: tmdbId, season_number: el.season_number })
.then((res) => {
const meta = res.episodes.map((el, index) => {
return {
id: `${tmdbId}:${el.season_number}:${el.episode_number}`,
name: `${el.name}`,
season: `${el.season_number}`,
number: `${el.episode_number}`,
episode: `${el.episode_number}`,
thumbnail: `https://image.tmdb.org/t/p/original${el.still_path}`,
overview: `${el.overview}`,
description: `${el.overview}`,
rating: `${el.vote_average}`,
firstAired: el.air_date,
released: el.air_date,
}
})
return meta
})
.catch(console.error);
return season
});
console.log(await episodes)
return episodes;
}
you are making a mess with the Law... I advise you to read more on https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
– anon
instead of Season = moviedb.... then(). catch(), you should either use a await Movie.. without the then.catch, or about the entire function with a Promise and call the resolver()/Reject(), at the end of the chain from then,catch,e a await for this file, if the function is asynchronous...
– anon
You can use
await
thusconst season = await moviedb
, but the place you call also has to be async. The important thing is to understand how callbacks https://answall.com/q/45706/3635 works and to understand how Promises: https://answall.com/q/119907/3635– Guilherme Nascimento