React Native无法在异步函数中正确设置timouts

时间:2019-02-05 12:23:55

标签: javascript react-native ecmascript-6 async-await es6-promise

我有以下操作:

const someAction = async () => {

    // t=0s: logs 'one'
    console.log('one');

    // wait 1000ms for the promise to resolve
    await new Promise(resolve => setTimeout(resolve, 1000));

    // t=1s: logs 'two'
    console.log('two');

    // will log 'three' at t=2s
    setTimeout(() => console.log('three'), 1000);

}

在普通浏览器中,其行为与注释中描述的行为相同。但是,当在我的Android手机上运行时,这三个日志几乎立即发生,顺序为“一个”,“两个”,“三个”。怎么了?是错误还是我做错了什么?


更新:三个相关问题(#22620#22620#22620)的使用似乎指向使用devtools时setTimeouts有一个React Native错误)

0 个答案:

没有答案