首页 > 解决方案 > 未来未在 PostgreSQL + Dart 上完成

问题描述

我有以下代码:

void main() async {
  connection = PostgreSQLConnection('localhost', 5432, 'db', username: 'postgres', password: '12345');
  await connection.open();
  
  //... 
  // some http handler that have next code inside:
  List<List<dynamic>> result = await connection.query(body['sql']).timeout(Duration(seconds: 90));

如果我对 http 处理程序运行大量查询,则会收到错误消息:

TimeoutException after 0:00:30.000000: Future not completed

这很奇怪,因为query我有 timeout 90 seconds。所以它发生在connection. 但我只打开一次连接main

有人可以解释它是如何发生的吗?以及如何解决?

标签: postgresqldart

解决方案


PostgreSQLConnection 有参数:timeoutInSecondsqueryTimeoutInSeconds,它们都默认为 30。我建议你使用它们而不是 Future 的 timeout。


推荐阅读