A voir également:
- Promise, await/async ou callback
- Uncaught (in promise) domexception: the operation is insecure. ✓ - Forum Javascript
- Uncaught (in promise) syntaxerror: json.parse: unexpected end of data at line 1 column 1 of the json data ✓ - Forum Javascript
- Sink to receive asynchronous callback - Forum Windows Vista
- 100 méga numéricable:ma vitesse est bien celle qui est promise? ✓ - Forum Réseaux sociaux
- Bean validation constraint(s) violated while executing automatic bean validation on callback event:'prepersist'. please refer to embedded constraintviolations for details. ✓ - Forum Java
1 réponse
Utilisateur anonyme
Modifié le 3 nov. 2019 à 21:00
Modifié le 3 nov. 2019 à 21:00
Salut,
avec la callback,
Avec un promesse:
avec la callback,
function getNotificationSounds2(serialOrName, idSound, callback) { console.log("1"); this.getNotificationSounds(serialOrName, (err, res) => { if (err) { console.log(err); return; } res.notificationSounds.forEach(function (item, index) { if (item['id'] == idSound) { callback(item); } }); }); } getNotificationSounds2('plock', 1, (result) => { console.log(result); });
Avec un promesse:
const getNotificationSounds2 = (serialOrName, idSound) => new Promise((resolve, reject) => { this.getNotificationSounds(serialOrName, (err, res) => { if (err) { reject(err); } res.notificationSounds.forEach((item, index) => { if (item['id'] == idSound) { resolve(item); } }); reject(new Error("Not found")); }); }); getNotificationSounds2('plock', 1) .then((result) => { console.log(result); }).catch((err) => { console.log(err); });