Currently, I am working with two files. One file contains a script that generates a token, while the other file handles that token.
The issue arises with the second script, as it only logs the initial token received and does not update with any new values.
This is how I am managing the token:
const first_file = require("./first_file.js");
first_file.first_file().then((res) => {
console.log(res);
});
Obviously, this approach will not suffice because it does not reflect the updated value of the token.
first_file = async () => {
return new Promise(async (resolve, reject) => {
//Generating the token
(async () => {
while (true) {
console.log("Resolving...");
resolve(token);
await sleep(5000);
resolved_token = token;
}
})();
});
};
module.exports = { first_file };
In an attempt to continuously resolve the token, I implemented a while..loop
. However, this method proved unsuccessful. Is there a more efficient way to directly export the variable for easier execution?