2016-08-26 1 views
0

Я использую эту функцию для вызова в другом Promise.all. Но я всегда получаю это предупреждение: Предупреждение: обещание было создано в обработчике, но не было возвращено из него. Также функция deleteFutureAppointments(), похоже, выходит из оригинального обещания. All и начинает делать другие работы в этой цепочке prom.all.Promise.all внутри другого Promise.all, кажется, выходит до его завершения и показывает предупреждение о том, что он не возвращается с обещания.

function deleteFutureAppointments() { 
 
Appointment.findAll(
 
{ where: 
 
    { 
 
     pro_id, client_id, from_datetime_utc: { 
 
      $gt: new Date() 
 
     } 
 
    } 
 
}) 
 
.then((appointments) => { 
 
    if (!appointments) { 
 
     return new Promise((resolve) => resolve()); 
 
    }   
 
    const promises = appointments.map((id) => { 
 
     const appointmentQuery = { where: { client_id } }; 
 
     const appointmentSMIQuery = { where: { appointment_id: id.get("appointment_id") } }; 
 
     return AppointmentMedia.destroy(appointmentSMIQuery) 
 
     .then((result) => { 
 
      if (result) { 
 
       removeAppointmentMedia.push(id.get("appointment_id")); 
 
      } 
 
      AppointmentService.destroy(appointmentSMIQuery); 
 
     }) 
 
     .then(() => IndexAppointmentCalendar.destroy(appointmentSMIQuery)) 
 
     .then(() => Appointment.destroy(appointmentQuery)); 
 
    }); 
 
    return Promise.all(promises); 
 
}) 
 
.catch((err) => { 
 
    next(err); 
 
}); 
 
}

+0

https://pouchdb.com/2015/05/18/we-have-a-problem-with-promises.html может помочь – Iiridayn

ответ

2

Похоже, вы не return ТРАЕКТОРИЙ Promise из AppointmentService.destroy - может быть ваша проблема. Я бы реструктурировать как:

function deleteFutureAppointments() { 
 
    Appointment.findAll({ where: { 
 
    pro_id, client_id, 
 
    from_datetime_utc: { $gt: new Date() } 
 
    } }).then(appointments => { 
 
    return Promise.all(appointments.map(appointment => { 
 
     var id = appointment.get("appointment_id"); 
 
     const appointmentSMIQuery = { where: { 
 
     appointment_id: id 
 
     } }; 
 
     return AppointmentMedia.destroy(appointmentSMIQuery).then(result => { 
 
     if (result) 
 
      removeAppointmentMedia.push(id); 
 
     return AppointmentService.destroy(appointmentSMIQuery); 
 
     }) 
 
     .then(() => IndexAppointmentCalendar.destroy(appointmentSMIQuery)) 
 
     .then(() => Appointment.destroy({ where: { client_id } })); 
 
    })); 
 
    }) 
 
    .catch((err) => { 
 
    next(err); 
 
    }); 
 
}

Смежные вопросы