TypeORM 保存冻结/阻止所有其他线程

And*_*ith 5 typescript typeorm

我将 typeorm 与 nativescript 应用程序一起使用。当我将数据更新到本地数据库时,我希望运行一个计时器。所以我在调用entitymanager.save之前启动计时器。计时器运行 1 - 2 秒...冻结..然后在查询完成后继续运行。

这样做的目的是,当用户等待更新插入完成时,我可以在主屏幕上显示或隐藏图标。

有没有办法让计时器在 typeorm 执行任务时继续运行?

我尝试过 1. 将 .save 方法包装在可观察对象中。2. 将计时器包装在 Promise 中


public uploadAllCodes() {
  let intervalId = setInterval(() => {
  this.counter = this.counter + 1;
  console.log(this.counter);
    if (this.counter === 25) {
      clearInterval(intervalId);
    }
  }, 1000);


  try {
    await this.Upsert(Codes, this.codes);
  } catch (e) {
    await alert(e);
  }

}

static async Upsert(EntityType: any, Entity: any) {
        let databaseConnection = await this.GetDatabaseConnection();

        await databaseConnection.manager.transaction(async manager => {
            await manager.save(EntityType, Entity, {
                listeners: false,
                chunk: 1000
            });
        });

    }
Run Code Online (Sandbox Code Playgroud)

我只是想知道是否有一种方法可以让计时器在更新插入发生时继续运行。