0
 async function checkStreamStatus(channelName) {
  const response = await  fetch(`https://api.twitch.tv/helix/streams?user_login=${channelName}`,  {

    headers: {
      'Authorization': 'Bearer ' + '',
      'Client-Id': '',
      
    }});

  const json = await response.json();
  const type = json.data[0]?.type;
  
  status = type;
  //console.log("worked " + status)
  
  if (status === "live") {
    return true;
  }
  else {
    return false;
  }
  
  
 }

My brain couldn't handle how async function works even i watched 3 videos and spent 3 hours how can i return true and false from this function

enter image description here

Krivi S
  • 1
  • 1
  • I read nearly all of these but i can't understand if someone can convert my example to working one i hope i can learn – Krivi S May 17 '22 at 23:45
  • 1
    You `await` the function call. – SuperStormer May 17 '22 at 23:51
  • If its async it means you can only a promise, in this case you return a promise that the value in its .then function would be a boolean. Whats the problem? – Yftach May 17 '22 at 23:52
  • what a website people can choose my problem is solved, really i know understand why people only uses this website at reading only mode – Krivi S May 17 '22 at 23:56
  • 1
    your code is correct, the issue is probably with the way you call `checkStreamStatus()`. Could you add the example of how you call your `checkStreamStatus` function? – Vitalii May 18 '22 at 00:00
  • 1
    Krivi, there are tons of questions answered about JS promises. An async question returns a promise, so you can't directly return a boolean value. You need to "thenize" the call of an async function in order to get its return value, since when an async function returns something it means the promise it returns is in fulfilled/rejected state. If you are confused about promises try to get the basics of the argument by reading some documentation. – Cesare Polonara May 18 '22 at 00:13

0 Answers0