creating.mjs
This commit is contained in:
@@ -64,6 +64,8 @@ export function allPromises(){
|
|||||||
let userTypes = axios.get("http://localhost:3000/userTypes")
|
let userTypes = axios.get("http://localhost:3000/userTypes")
|
||||||
let addressTypes = axios.get("http://localhost:3000/addressTypes")
|
let addressTypes = axios.get("http://localhost:3000/addressTypes")
|
||||||
|
|
||||||
|
// wait until all promises
|
||||||
|
// fulfilled or one is rejected
|
||||||
Promise.all([categories, statuses, userTypes, addressTypes])
|
Promise.all([categories, statuses, userTypes, addressTypes])
|
||||||
.then(([cat, stat, type, address]) => {
|
.then(([cat, stat, type, address]) => {
|
||||||
setText("");
|
setText("");
|
||||||
@@ -82,6 +84,8 @@ export function allSettled(){
|
|||||||
let userTypes = axios.get("http://localhost:3000/userTypes")
|
let userTypes = axios.get("http://localhost:3000/userTypes")
|
||||||
let addressTypes = axios.get("http://localhost:3000/addressTypes")
|
let addressTypes = axios.get("http://localhost:3000/addressTypes")
|
||||||
|
|
||||||
|
// wait until all are
|
||||||
|
// fulfilled or rejected
|
||||||
Promise.allSettled([categories, statuses, userTypes, addressTypes])
|
Promise.allSettled([categories, statuses, userTypes, addressTypes])
|
||||||
.then((values) => {
|
.then((values) => {
|
||||||
let results = values.map(v => {
|
let results = values.map(v => {
|
||||||
@@ -101,6 +105,7 @@ export function race(){
|
|||||||
let users = axios.get("http://localhost:3000/users")
|
let users = axios.get("http://localhost:3000/users")
|
||||||
let backup = axios.get("http://localhost:3001/backup")
|
let backup = axios.get("http://localhost:3001/backup")
|
||||||
|
|
||||||
|
// return fastest promise
|
||||||
Promise.race([users, backup])
|
Promise.race([users, backup])
|
||||||
.then(users => setText(JSON.stringify(users.data)))
|
.then(users => setText(JSON.stringify(users.data)))
|
||||||
.catch(error => setText(error))
|
.catch(error => setText(error))
|
||||||
|
|||||||
Reference in New Issue
Block a user