Skip to content

Commit 3eb3b97

Browse files
authored
Add query/request timeout support (#589)
* Support query timeout * Add tests for timeout * Add browser support for timeout * Document timeout
1 parent 5a39558 commit 3eb3b97

File tree

8 files changed

+130
-77
lines changed

8 files changed

+130
-77
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1515
implemented in the current ArangoDB 3.4 release candidate. Please note that this API
1616
is still subject to change and may indeed still change until the 3.4.0 GA release.
1717

18+
### Added
19+
20+
- Added `timeout` option to `db.query` and request methods
21+
22+
Note that this merely cancels the request. Queries will still be executed
23+
and ArangoDB will still continue processing the request, this will merely
24+
result in the socket being forcefully disconnected.
25+
1826
## [6.9.0] - 2018-11-07
1927

2028
### Changed

docs/Drivers/JS/Reference/Database/Queries.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ Dirty reads are only available when targeting ArangoDB 3.4 or later,
4747
see [Compatibility](../../GettingStarted/README.md#compatibility).
4848
{% endhint %}
4949

50+
Additionally _opts.timeout_ can be set to a non-negative number to force the
51+
request to be cancelled after that amount of milliseconds. Note that this will
52+
simply close the connection and not result in the actual query being cancelled
53+
in ArangoDB, the query will still be executed to completion and continue to
54+
consume resources in the database or cluster.
55+
5056
If _query_ is an object with _query_ and _bindVars_ properties, those will be
5157
used as the values of the respective arguments instead.
5258

@@ -67,10 +73,9 @@ const cursor = await db.query(aql`
6773
// -- or --
6874

6975
// Old-school JS with explicit bindVars:
70-
db.query(
71-
"FOR u IN _users FILTER u.authData.active == @active RETURN u.user",
72-
{ active: true }
73-
).then(function(cursor) {
76+
db.query("FOR u IN _users FILTER u.authData.active == @active RETURN u.user", {
77+
active: true
78+
}).then(function(cursor) {
7479
// cursor is a cursor for the query result
7580
});
7681
```

0 commit comments

Comments
 (0)