Answer the question
In order to leave comments, you need to log in
Why do Promises work weird?
Good afternoon!
There is such a design:
const getData = async (data) => {
data = JSON.parse(data);
const promises = await data.bloggers.map((item) => getInfo(response.access_token, item.twitch_nickname));
return Promise.all(promises);
};
getData(data).then(data => console.log(data));
async function getInfo(token, name) {
const response = await axios.get(`https://api.twitch.tv/helix/streams?user_login=${name}`, {
headers: {
'Client-Id': '1uv0rg1z4x',
'Authorization': `Bearer ${token}`
},
});
let isLive = response.data.data.length != 0 ? true : false;
return isLive;
}
...
const promises = await data.bloggers.map((item) => {
getInfo(response.access_token, item.twitch_nickname);
});
...
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question