Как написать тайм-аут для firestore на флаттере? - PullRequest
0 голосов
/ 07 мая 2020

Когда я обновляю данные firestore без подключения inte rnet. он просто застрял там. как отключить запрос хранилища огня. или как это лучше всего сделать?

try {
  await userRef.document(uid).updateData({ 
    "data": data 
  });
  return Response.isSuccess({});
} catch(err) {
  print(err);
  return Response.isError(err);
}

Ответы [ 2 ]

0 голосов
/ 07 мая 2020

Попробуйте использовать транзакции, вы можете установить время ожидания.

await Firestore.instance.runTransaction((Transaction tx) {

await tx.get / set / update 

}).timeout(Duration(seconds: 1), onTimeout: () {

print('Timed out');

});
0 голосов
/ 07 мая 2020

В firestore есть метод тайм-аута.

 await userRef.document(uid).updateData({ 
    "data": data 
  }).timeout(Duration(seconds: 1));
...