我有一个用于与IndexedDB进行交互的对象。它有一个属性,当数据库完成打开时,它会更改为2。我如何告诉read方法等待this.ready == 2?使方法暂停,直到另一个属性准备好
var db = {
open: function() {//a callback sets this.ready to 2 when the database has been successfully opened},
ready: 0,
read: function() {
if(!this.ready == 2) {//pause until this.ready == 2}
...
}
}
我应该写一个函数中使用的setTimeout来检查this.ready每隔100毫秒或者是有一个更优雅的解决方案?
这可能有助于http://stackoverflow.com/questions/5346694/how-to-implement-a-lock-in-javascript – Tija