我将 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: …Run Code Online (Sandbox Code Playgroud) 静电主要在这里
string[] dayNames = { "Sun", "Mon", "Tues", "Wed", "Thur", "Fri", "Sat" };
string m = "";
double average = 0;
double total = 0;
int[] bCalories = new int[7];
int[] lCalories = new int[7];
int[] dCalories = new int[7];
int[] dayTotal = new int[7];
for (int i = 0; i < 7; i++)
{
Console.Write("Please enter calories for {0} breakfast: ", dayNames[i]);
bCalories[i] = int.Parse(Console.ReadLine());
Console.Write("Please enter calories for {0} lunch: ", dayNames[i]);
lCalories[i] = int.Parse(Console.ReadLine());
Console.Write("Please enter calories …Run Code Online (Sandbox Code Playgroud)