0

I'm trying to use nodejs to run a loop functions oh_lawd_it_chonky() that is supposed to do the following: Loop target_users array passing each user to initialize() for authorization, for each given user get data using returnbigdatachunk() take that data and refine it or do something to it using process_returnbigdatachunk() push each of the results of that for each user to an array output.

I have each of the initialize(), returnbigdatachunk() and process_returnbigdatachunk() working individually and so I've omitted the details of those functions for the sake of simplicity in this post, I just can't seem to get the darn oh_lawd_it_chonky() function working. I don't quite understand how to pass through the user parameters correctly in nested functions like this. Please help if you can! Sorry this isn't quite a working example.

const target_users = ['user1', 'user2', 'user3'];

//authorize each user
function initialize(user) {
//do the stuff to get authorization
}

//loop through all the users and build an array of all the process_returnbigdatachunk
const oh_lawd_it_chonky = async () => {
for (var f = 0; f < target_users; f++) {
try {

  //get data of passed in user
  const returnbigdatachunk = async () => {
    const auth = initialize(user[target_users[f]]);

    let output = [];

    //refine data of passed in user
    const process_returnbigdatachunk = async () => {
        try {
          const data = await returnbigdatachunk();

          //push refined data into output array
          output.push(process_returnbigdatachunk)     
          console.log("crampus: " + output)
        } catch (e) {
          console.error('Failed to process returnbigdatachunk', e);
        }
      };
  };
} catch (e) {
  console.error('Failed to process returnbigdatachunk', e);
}
}
};
W.Lyman
  • 357
  • 1
  • 9
  • `const nameOfFunction = singleParam => {/* ... */}` or `const nameOfFunction = (param1, param2, { destructuring }, ...spread) => {/* ... */}`. – code Mar 08 '22 at 21:41
  • I'm trying to interpret the meaning of 'spread' and 'destructuring', and where these name0fFunction would go. Sorry I'm pretty new still. – W.Lyman Mar 08 '22 at 21:48
  • Replace `nameOfFunction` with whatever you will, e.g. `oh_lawd_it_chonky`. You can ignore the spread and destructuring part (or google it). – code Mar 08 '22 at 21:51

1 Answers1

0

setTimeout in for-loop does not print consecutive values

block-scoped change you var f = 0 to let f = 0

rookie
  • 128
  • 4