Compare commits
3 Commits
488fe1772c
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b33f9e73f | ||
|
|
71aaa607b9 | ||
|
|
3cb77be647 |
3190
package-lock.json
generated
3190
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,16 +1,58 @@
|
|||||||
import setText, { appendText, showWaiting, hideWaiting } from "./results.mjs";
|
import setText, { appendText, showWaiting, hideWaiting } from "./results.mjs";
|
||||||
|
|
||||||
export function get() {
|
export function get() {
|
||||||
|
axios.get("http://localhost:3000/orders/1")
|
||||||
|
.then(({ data }) => {
|
||||||
|
setText(JSON.stringify(data));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCatch() {
|
export function getCatch() {
|
||||||
|
axios.get("http://localhost:3000/orders/123")
|
||||||
|
.then(({ data }) => {
|
||||||
|
setText(JSON.stringify(data));
|
||||||
|
})
|
||||||
|
.catch(err => setText(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function chain() {
|
export function chain() {
|
||||||
|
axios.get("http://localhost:3000/orders/1")
|
||||||
|
.then(({ data }) => {
|
||||||
|
return axios.get(`http://localhost:3000/addresses/${data.shippingAddress}`);
|
||||||
|
})
|
||||||
|
.then(({data}) => {
|
||||||
|
setText(`City: ${data.city}`);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function chainCatch() {
|
export function chainCatch() {
|
||||||
|
axios.get("http://localhost:3000/orders/1")
|
||||||
|
.then(({ data }) => {
|
||||||
|
axios.get(`http://localhost:3000/addresses/${data.shippingAddress}`);
|
||||||
|
})
|
||||||
|
.then(({data}) => {
|
||||||
|
setText(`City: ${data.city}`);
|
||||||
|
})
|
||||||
|
.catch(err => setText(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function final() {
|
export function final() {
|
||||||
|
|
||||||
|
showWaiting();
|
||||||
|
|
||||||
|
axios.get("http://localhost:3000/orders/1")
|
||||||
|
.then(({ data }) => {
|
||||||
|
return axios.get(`http://localhost:3000/addresses/${data.shippingAddress}`);
|
||||||
|
})
|
||||||
|
.then(({data}) => {
|
||||||
|
setText(`City: ${data.city}`);
|
||||||
|
})
|
||||||
|
.catch(err => setText(err))
|
||||||
|
.finally(() => {
|
||||||
|
setTimeout(() => {
|
||||||
|
hideWaiting();
|
||||||
|
}, 1500);
|
||||||
|
|
||||||
|
appendText(" -- Completely Done ");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
@@ -1,21 +1,104 @@
|
|||||||
import setText, { appendText } from "./results.mjs";
|
import setText, { appendText } from "./results.mjs";
|
||||||
|
|
||||||
export function timeout() {
|
export function timeout() {
|
||||||
|
const wait = new Promise((resolve) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
resolve("Timeout !");
|
||||||
|
}, 1500)
|
||||||
|
});
|
||||||
|
|
||||||
|
wait.then(text => setText(text))
|
||||||
}
|
}
|
||||||
|
|
||||||
export function interval() {
|
export function interval() {
|
||||||
|
let counter = 0;
|
||||||
|
const wait = new Promise((resolve) => {
|
||||||
|
setInterval(() => {
|
||||||
|
console.log(`Counter ${++counter}`);
|
||||||
|
resolve(`Counter ${counter}`);
|
||||||
|
}, 1500)
|
||||||
|
});
|
||||||
|
|
||||||
|
wait
|
||||||
|
.then(text => setText(text))
|
||||||
|
.finally(() => appendText(`-- DONE COUNTER ${counter}`));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function clearIntervalChain() {
|
export function clearIntervalChain() {
|
||||||
|
|
||||||
|
let counter = 0;
|
||||||
|
let interval;
|
||||||
|
const wait = new Promise((resolve) => {
|
||||||
|
interval = setInterval(() => {
|
||||||
|
console.log(`Counter ${++counter}`);
|
||||||
|
resolve(`Counter ${counter}`);
|
||||||
|
}, 1500)
|
||||||
|
});
|
||||||
|
|
||||||
|
wait
|
||||||
|
.then(text => setText(text))
|
||||||
|
.finally(() => clearInterval(interval));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function xhr() {
|
export function xhr() {
|
||||||
|
|
||||||
|
let request = new Promise((resolve, reject) => {
|
||||||
|
let oReq = new XMLHttpRequest();
|
||||||
|
oReq.open("GET", "http://localhost:3000/users/7");
|
||||||
|
oReq.onload = () => {
|
||||||
|
if (oReq.status === 200) {
|
||||||
|
resolve(oReq.responseText);
|
||||||
|
} else {
|
||||||
|
reject(oReq.statusText + " " + oReq.status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
oReq.onerror = () => reject("Request Failed !")
|
||||||
|
oReq.send();
|
||||||
|
});
|
||||||
|
|
||||||
|
request.then(result => setText(result))
|
||||||
|
.catch(reason => setText(reason));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function allPromises() {
|
export function allPromises() {
|
||||||
|
let categories = axios.get("http://localhost:3000/itemCategories");
|
||||||
|
let statuses = axios.get("http://localhost:3000/orderStatuses");
|
||||||
|
let userTypes = axios.get("http://localhost:3000/userTypes");
|
||||||
|
let addressType = axios.get("http://localhost:3000/addressTypes");
|
||||||
|
Promise.all([categories, statuses, userTypes, addressType])
|
||||||
|
.then(([cat, stat, type, addr]) => {
|
||||||
|
setText("");
|
||||||
|
|
||||||
|
appendText(JSON.stringify(cat.data));
|
||||||
|
appendText(JSON.stringify(stat.data));
|
||||||
|
appendText(JSON.stringify(type.data));
|
||||||
|
appendText(JSON.appendText(addr.data));
|
||||||
|
})
|
||||||
|
.catch(reasons => setText(reasons));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function allSettled() {
|
export function allSettled() {
|
||||||
|
let categories = axios.get("http://localhost:3000/itemCategories");
|
||||||
|
let statuses = axios.get("http://localhost:3000/orderStatuses");
|
||||||
|
let userTypes = axios.get("http://localhost:3000/userTypes");
|
||||||
|
let addressType = axios.get("http://localhost:3000/addressTypes");
|
||||||
|
|
||||||
|
Promise.allSettled([categories, statuses, userTypes, addressType])
|
||||||
|
.then((values) => {
|
||||||
|
let results = values.map(v => {
|
||||||
|
if (v.status === 'fulfilled'){
|
||||||
|
return `FULLFILLED ${JSON.stringify(v.value.data[0])} `;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `REJECTED : ${v.reason.message} `;
|
||||||
|
});
|
||||||
|
|
||||||
|
setText(results)
|
||||||
|
})
|
||||||
|
.catch(toto => setText(toto));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function race() {
|
export function race() {
|
||||||
|
|||||||
@@ -1,16 +1,53 @@
|
|||||||
import setText, { appendText } from './results.mjs';
|
import setText, { appendText } from './results.mjs';
|
||||||
|
|
||||||
export function get(){
|
export async function get() {
|
||||||
|
const { data } = await axios.get("http://localhost:3000/orders/1");
|
||||||
|
setText(JSON.stringify(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCatch(){
|
export async function getCatch() {
|
||||||
|
try {
|
||||||
|
const { data } = await axios.get("http://localhost:3000/orders/123");
|
||||||
|
setText(JSON.stringify(data));
|
||||||
|
} catch(error) {
|
||||||
|
setText(error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function chain(){
|
export async function chain() {
|
||||||
|
|
||||||
|
const {data} = await axios.get("http://localhost:3000/orders/1");
|
||||||
|
const {data: address} = await axios.get(`http://localhost:3000/addresses/${data.shippingAddress}`);
|
||||||
|
|
||||||
|
setText(`City: ${JSON.stringify(address.city)}`);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function concurrent(){
|
export async function concurrent() {
|
||||||
|
|
||||||
|
const orderStatuses = axios.get("http://localhost:3000/orderStatuses");
|
||||||
|
const orders = axios.get("http://localhost:3000/orders");
|
||||||
|
|
||||||
|
const {data: statuses} = await orderStatuses;
|
||||||
|
const {data: order} = await orders;
|
||||||
|
|
||||||
|
appendText(JSON.stringify(statuses));
|
||||||
|
appendText(JSON.stringify(order[0]));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parallel(){
|
export async function parallel() {
|
||||||
|
|
||||||
|
setText("")
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
(async () => {
|
||||||
|
const { data } = await axios.get("http://localhost:3000/orderStatuses");
|
||||||
|
appendText(JSON.stringify(data));
|
||||||
|
}) (),
|
||||||
|
(async () => {
|
||||||
|
const { data } = await axios.get("http://localhost:3000/orders");
|
||||||
|
appendText(JSON.stringify(data));
|
||||||
|
}) ()
|
||||||
|
])
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user