Skip to content

Commit

Permalink
Added for loop instead of foreach
Browse files Browse the repository at this point in the history
Aakash Thaiwat authored and Aakash Thaiwat committed May 19, 2020
1 parent 3412beb commit b38b43e
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -57,7 +57,7 @@ function authorize(credentials, callback, params) {
callback(oAuth2Client, params);
}

function writeUsers(auth, params) {
async function writeUsers(auth, params) {
const sheets = google.sheets({ version: 'v4', auth });
let values = [];

@@ -86,9 +86,12 @@ function writeUsers(auth, params) {

sheets.spreadsheets.values.update(req).then((res) => console.log(res.data));
console.log(sendList);
sendList.forEach(u => {
sendMessage(u, temperatureStrings[Math.floor(Math.random() * temperatureStrings.length)]);
});
// sendList.forEach(u => {
// sendMessage(u, temperatureStrings[Math.floor(Math.random() * temperatureStrings.length)]);
// });
for (let u of sendList) {
await sendMessage(u, temperatureStrings[Math.floor(Math.random() * temperatureStrings.length)]);
}
}

const resolveEmailsAndUpdateSheet = async (params) => {
@@ -152,7 +155,7 @@ function writeTemp(auth, params) {
sheets.spreadsheets.values.append(req).then((res) => console.log(res.data));
}

function sendMessage(u, m) {
async function sendMessage(u, m) {
(async () => {
console.log(`Sending message to ${u}`);
// Post a message to the channel, and await the result.
@@ -170,6 +173,7 @@ function sendMessage(u, m) {
} else {
console.log(`Failed to send message in conversation ${u}`);
}
return result;
})();
}

0 comments on commit b38b43e

Please sign in to comment.