js async promise code example
Example 1: async awiat
const data = async () => {
const got = await fetch('https://jsonplaceholder.typicode.com/todos/1');
console.log(await got.json())
}
data();
Example 2: promise.all async await
async function fetchABC() {
const [a, b, c] = await Promise.all([a(), b(), c()]);
}
Example 3: nodejs promise async
function square(x) {
return new Promise(resolve => {
setTimeout(() => {
resolve(Math.pow(x, 2));
}, 2000);
});
}
async function layer(x)
{
const value = await square(x);
console.log(value);
}
layer(10);
Example 4: nodejs promise async
function add(a,b){
return a + b;
}
async function add(a,b){
return a + b;
}
Example 5: await async
function afterPrintSave() {
Xrm.Page.data.save().then(
function () {
resolve();
},
function (err) {
resolve(alert(err.message));
}
);
}