Proper way to loop for a promise response

I have a primary and secondary sms service for my app. If the primary fails, for any issue, I want to default to the secondary service.

I have a primary and secondary sms service for my app. If the primary fails, for any issue, I want to default to the secondary service.

Here is the flow:

  1. send to sms service
  2. sms service responds with receipt acknowledgement
  3. sms service sends message to phone carrier
  4. sms service receives phone carrier receipt
  5. my app can then query sms service for carrier receipt

However, due to the time frames involved (internet, carrier delays, etc), I need to loop #5 until the carrier receipt comes in...or times out...to determine if it needs to go to the secondary service. Currently I am doing a 3 second timeout delay before querying for #5 - but I would like to convert that to a 1 second loop to ensure that if #4 takes longer than 3 seconds that my #5 will still working correctly.

  $scope.sendCode = function() {
    $scope.errColor = "red" ;
    $scope.errMsg = "SENDING AUTH CODE" ;
    var newCode = getRandom(10000,99999) ;
    //var tktCode = new Date().format("yyyymmdd")+ "_" +getRandom(10000,999999) ;
    var smsNumber = getDB("user_phone") ;
    setDB("app_regCode",newCode) ;
    var msg = "App registration code: "+newCode+ ". Enter this code into the 'VERIFY CODE' input field" ;
    var tReq = twilio(smsNumber,msg) ;
var smsCarrier = getDB("dev_carrier") ;
if (!smsCarrier) {
  smsCarrier = "No Carrier Info" ;
}
var smsEmail = $scope.userObj.user_email ;
if (!smsEmail) {
  smsEmail = "No Email" ;
}

$scope.errColor ;
$scope.errMsg ;
var error = {} ;  
var smsShortCode = vendorData.twilioShortCode ;
var smsLongCode = vendorData.twilioLongCode ;  
// log message sent to internal API
$scope.smsID = logSMS(smsNumber,smsLongCode,smsShortCode,msg,smsCarrier,smsEmail,"Twilio") ;
$http(tReq).then(function(response) {
  $scope.errColor = "green" ;
  $scope.errMsg = "SENT!  Confirming Delivery" ;
  smsResponse = response.data ;
  if (smsResponse.sid) {
    //update smsSent record
    apiService.all("PUT",[{table:"smsSent",sid:"rid",sidValue:$scope.smsID,soloField:1,dataInfo:{smsTkt:smsResponse.sid}}]) ;
  }
  if (smsResponse.status.match(/(queued|accepted|sending|sent)/i)) {  //if (sms.success == true) {

    // need to replace this with a proper 1 second loop
    // to test for "delivered" carrier receipt
    // if status still (queued|accepted|sending|sent), then loop until its updated
    // final receipt statuses are: Delivered, Undelivered, Failed

    setTimeout(function() {  
      return $http(twilioVerify(smsResponse.uri))
      .then(function(response) {
        // now check status of message to determine if needed to exit or go to back up service
        //return $http(twilioVerify(smsResponse.uri))
        if (response.data.status == "delivered") {
          $scope.errColor = "green"
          $scope.errMsg = "Delivery Confirmed" ;
          messageSent('Primary');
        } else {
          //backup service
          // determine fail reason, send to secondary if necessary
          messageFail('Primary') ;
          $scope.errColor = "red"
          $scope.errMsg = "Problem detected, trying secondary service" ;              
          secondSMS(smsNumber,msg) ;
        }
      }) ;
    },3000) ;

  } else {  // failed response from Twilio, send to MissionMobile
    $scope.errColor = "red" ;
    $scope.errMsg = "Problem detected, attempting secondary service"
    messageFail('Primary') ;
    secondarySMS(smsNumber,msg) ;
  }
}, function(thisError) {  // failed communication to Twilio, send to MissionMobile
    $scope.errColor = "red" ;
    $scope.errMsg = "Issue sending code, attempting secondary service" ;
    messageFail('Primary') ;
    secondarySMS(smsNumber,msg) ;
}).catch(function(error) {
    $scope.errColor = error.errColor ;
    $scope.errMsg = error.errMsg ;
}) ;

}


What are the differences between the various JavaScript frameworks? E.g. Vue.js, Angular.js, React.js

What are the differences? Do they each have specific use contexts?

What are the differences? Do they each have specific use contexts?