postgresql - 未来未在 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
。
有人可以解释它是如何发生的吗?以及如何解决?
解决方案
PostgreSQLConnection 有参数:timeoutInSeconds和queryTimeoutInSeconds,它们都默认为 30。我建议你使用它们而不是 Future 的 timeout。
推荐阅读
- sql - 用户登录后立即发送消息的时间百分比是多少?
- node.js - 错误:TypeError [ERR_INVALID_REPL_INPUT]:“uncaughtException”的侦听器不能在 Object.compile 的 REPL 中使用
- java - 使我的椭圆成为按钮以在同一窗口上显示一些数据?
- kubernetes - kubectl 端口转发和 NodePort 服务的区别
- node.js - 为什么在 Node.js 中阻塞文件 I/O 时异步性能更差?
- raspberry-pi3 - 通过代码重置 Raspberry Pi 3 Model B
- php - mysql选择不同并丢弃其他
- web-services - 我可以为我的网络服务使用端口 443 还是保留此端口?
- java - 我们如何从 gradle 中的 jar 文件加载共享库(.so)?
- vue.js - 无法使用 Vue2 Smooth Scroll 构建 Gridsome 网站