const someApiCall = async(data) => {
// 1. calls an api with a payload and that api runs an async task to update
const {id} = creationApi(data)
// 2. polls another api to see status of the async job above
let isComplete = false;
if (!isComplete) {
const status = await apiToPoll(id)
if (status === 'error') {
throw new Error('goodbye world')
} else if (status !== 'inProgress') {
isComplete = true
} else {
// delay for x ms
}
}
// 3. once poll completes with a status of success update another api with the payload
await updateOtherResourcesApi(id)
// 4. once that update is complete fetch data for other api's
const result = fetchDataApi(id)
// set result of fetch
setResult(result) // redux, local state, or whatever
}
const someApiCall = async(data) => {
// 1. calls an api with a payload and that api runs an async task to update
const {id} = creationApi(data)
// 2. polls another api to see status of the async job above
let isComplete = false;
if (!isComplete) {
const status = await apiToPoll(id)
if (status === 'error') {
throw new Error('goodbye world')
} else if (status !== 'inProgress') {
isComplete = true
} else {
// delay for x ms
}
}
// 3. once poll completes with a status of success update another api with the payload
await updateOtherResourcesApi(id)
// 4. once that update is complete fetch data for other api's
const result = fetchDataApi(id)
// set result of fetch
setResult(result) // redux, local state, or whatever
}