З🧟
Size: a a a
З🧟
В
В
п
З🧟
З🧟
DE
p
DE
DE
Н
DE
DE
DE
DE
Н
DE
DE
js
// define
function asyncFunction (id, callback) {
const result = Client.fetch(id);
callback(result);
}
// usage
asyncFunction(1, (result) => {
// do something with your result
})
js
// define
function asyncFunction (id) {
return new Promise((resolve, reject) => {
const result = Client.fetch(id);
if (result) {
return resolve(result);
}
reject(new Error('Can\'t get result!'));
});
}
// usage
asyncFunction(1)
.then( (result) => {
// do something with your result
})
.catch((error) => {
console.error(error);
});
DE
js
(async function() {
const result = await asyncFunction(1)
// do somethinng with your result
})();
DE