Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138279

React Native await promise never executes

$
0
0

I am trying to build a react-native bluetooth app, but this is my first time working with react-native. I have an asycn function that I am calling witch is calling await BluetoothSerial.discoverUnpairedDevices() but nothing happens it just waits. What am I missing?

Full function code

async discoverUnpaired () {
      if (this.state.discovering) {
        console.log("true: ", this.state.discovering)
        this.setState({ discovering: false })
        return false
      } else {
        this.setState({ discovering: true })
        try{
          console.log("false: ", this.state.discovering)
          await BluetoothSerial.discoverUnpairedDevices()
          .then((unpairedDevices) => {
            this.setState({ unpairedDevices, discovering: false })
            console.log("false: ", this.state.discovering)
          })
          .catch((err) => console.log(err.message))
          }
        catch(e){
          console.log(e)
        } 
      }
    }

P.S. Sorry for the bad code, just researching react-native bluetooth for a project. If anyone has a good tutorial for react-native classic bluetooth that would also help a lot.

EDIT

After changing the code to

const unpairedDevices = await BluetoothSerial.discoverUnpairedDevices();
this.setState({ unpairedDevices, discovering: false });
console.log("devices: ", unpairedDevices);

the problem is still there. I think that this is just a bug in the library because if call BluetoothSerial.list() instead of BluetoothSerial.discoverUnpairedDevices() it workes


Viewing all articles
Browse latest Browse all 138279

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>