Problem with Promise

Hello, I have a problem with promises in Adonis.

The request works once, but when executed again does not return nothing.

This is my code

function awsgetdata() {  
    return new Promise((resolve, reject) => {     
    thingShadows.on('connect', function () {
      console.log('connected');     
    thingShadows.register(device_name, {}, function () {
      console.log('Registered');   
        thingShadows.get(device_name);
        thingShadows.on('status',
          function (device_name, stat, clientToken, stateObject) {
            var responsedata = stateObject.state;
            if (responsedata.hasOwnProperty("reported")) {
            let  data = responsedata.reported.reported
              console.log('Data');  
              resolve(data)   
            }
          });
        });
      });    
    });
  }

class AquariumTempController {
async getTemp({response}){      
  await awsgetdata()
  .then((result) => { return response.status(200).send({ data: { message: 'success', data: result }})})
  .catch((err) => { return response.status(400).send({ data: { message: 'error',  data: err }})})  
  }
}

Hey @mtsmal! :wave:

Do you understand how async/await work?

1 Like