A voir également:
- Promise, await/async ou callback
- Exception in tkinter callback - Forum Python
- File source (async.)::output ✓ - Forum Vidéo/TV
- La terre promise chanson en anglais ✓ - Forum Musique / Radio / Clip
- 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
1 réponse
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);
});