beautifulpython
beautifulpython15mo ago

✅ – ✅ – beautifulpython – 19-38 Jul 25

greetings, I have a self referencing async function that populates a global array declared top of my code let final = [] But when I try to see it's value it still shows as []. Here is my code been at it for almost 4 hours and stuck
36 Replies
beautifulpython
beautifulpython15mo ago
async function drainTrino(nextUri) {
let response = await fetch(nextUri,
{
method: "GET",
mode: "cors",
cache: "no-cache",
credentials: "same-origin",
redirect: "follow",
referrerPolicy: "no-referrer",
headers: {
'accept': 'application/json',
'Authorization': 'Basic root'
}
}
)
let d = await response.json();

if (d.nextUri) {
if (d.data && d.columns) {
let o = {};
//let c = d.columns[0].name
//console.log('"' + c + '"')
for (let i = 0; i < d.data.length; i++) {

o["orderkey"] = d.data[i][0].toString();
o[`clerk`] = d.data[i][6];
o[`totalprice`] = d.data[i][3];
o[`orderdate`] = d.data[i][4];
orders.push(o)
}

}
drainTrino(d.nextUri)
} else {
return orders
}
}
async function drainTrino(nextUri) {
let response = await fetch(nextUri,
{
method: "GET",
mode: "cors",
cache: "no-cache",
credentials: "same-origin",
redirect: "follow",
referrerPolicy: "no-referrer",
headers: {
'accept': 'application/json',
'Authorization': 'Basic root'
}
}
)
let d = await response.json();

if (d.nextUri) {
if (d.data && d.columns) {
let o = {};
//let c = d.columns[0].name
//console.log('"' + c + '"')
for (let i = 0; i < d.data.length; i++) {

o["orderkey"] = d.data[i][0].toString();
o[`clerk`] = d.data[i][6];
o[`totalprice`] = d.data[i][3];
o[`orderdate`] = d.data[i][4];
orders.push(o)
}

}
drainTrino(d.nextUri)
} else {
return orders
}
}
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
beautifulpython
beautifulpython15mo ago
yes sir
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
beautifulpython
beautifulpython15mo ago
this is for trino database and when using rest api youknow it has ended or drained when d.nextUri is not longer there
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
beautifulpython
beautifulpython15mo ago
do I need some type of event listener for this onEnd ?
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
beautifulpython
beautifulpython15mo ago
ok let me read up on that how to implement sucj a thing. thnx! can this work?
() => {
return orders
};
() => {
return orders
};
oh wait it has to be passed on got it
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
beautifulpython
beautifulpython15mo ago
anonymous function no name
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
beautifulpython
beautifulpython15mo ago
i cant bcs its anonymous i need to naem it
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
beautifulpython
beautifulpython15mo ago
oh sorry. i was going to dump it here
drainTrino(d.nextUri)
} else {
() => {
return orders
};
}
drainTrino(d.nextUri)
} else {
() => {
return orders
};
}