0

nodejs file

var result= async function meet(){
    var link= undefined;
    
    calendar.events.insert({
        calendarId: 'primary', 
        conferenceDataVersion: '1', 
        resource: event 
    }, (err, temp) => {
        link = temp.data.hangoutLink; // I want to update link but it is not updating
    });

    return link;
}

console.log(result);//it shows undefined;
Yves Kipondo
  • 5,289
  • 1
  • 18
  • 31
Sumit Kumar
  • 183
  • 1
  • 9

2 Answers2

1

Do you use https://github.com/yuhong90/node-google-calendar?

Then insert is already returningn an promise:

var result= async function meet(){
    let link = await calendar.events.insert({
        calendarId: 'primary', 
        conferenceDataVersion: '1', 
        resource: event 
    })
    return link.data.hangoutLink
}

And please... if you put async infront of it will return you an promise.

Promises are thenable you can use .then() on it to get your result

result().then(res => {
   console.log(res);
})
bill.gates
  • 14,145
  • 3
  • 19
  • 47
0

You either look at async version of this function (if exists) and use it with await or then or you can wrap this call with a callback to new Promise like this:

 var link= await (new Promise(resolve, reject) => {
        calendar.events.insert(
            { calendarId: 'primary', conferenceDataVersion: '1', resource: event },
            (err, temp) => {
               if (err) {
                  reject(err)
               }
                resolve(temp.data.hangoutLink)
            })
   }));
    return link;
Anatoly
  • 20,799
  • 3
  • 28
  • 42