React-native: setTimeout is broken

Created on 26 Jul 2016  路  5Comments  路  Source: facebook/react-native

Not really sure here but somethign is fishy.. I am running on device via debug mode.

componentDidMount()` {
    console.log('Modal Mounts!')
    setTimeout(() => {
      console.log('Open')
      this.props.openModal()
    }, 10000)


  }

This will always fire instantly... about 100 ms

componentDidMount() {
    console.log('Modal Mounts!')
    setTimeout(() => {
      console.log('Open')
      this.props.openModal()
    }, 30000)


  }

Fires instantly as well

componentDidMount() {
    console.log('Modal Mounts!')
    setTimeout(() => {
      console.log('Open')
      this.props.openModal()
    }, 80000)


  }

Fires after about 30 seconds

Locked

Most helpful comment

Check that your device's time matches that of your computer! This happened to me and took an unfortunately long while to debug haha

All 5 comments

To further illustrate this problem...

console.log('In Modal')
setTimeout(() => console.log('Five Seconds'), 5000)

image

Check that your device's time matches that of your computer! This happened to me and took an unfortunately long while to debug haha

There is already an issue open for this. There doesn't seem to be any fix on the way however.

https://github.com/facebook/react-native/issues/4470

Looks like this is now fixed as discussed in https://github.com/facebook/react-native/issues/9436 .

@mangogogos Is correct. I had the problem of time drifting more than 60s and I corrected it but still there was a few seconds difference between the emulator and the system. Hilariously by the time I read his comment and looked back at the emulator I realized my code had actually executed after the delay.

Was this page helpful?
0 / 5 - 0 ratings