This repository has been archived by the owner on Jul 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: stop running queries on shutdown (#95)
- Loading branch information
1 parent
440b391
commit e137297
Showing
5 changed files
with
233 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use strict' | ||
|
||
/** | ||
* Keeps track of all running queries. | ||
*/ | ||
class QueryManager { | ||
/** | ||
* Creates a new QueryManager. | ||
*/ | ||
constructor () { | ||
this.queries = new Set() | ||
this.running = false | ||
} | ||
|
||
/** | ||
* Called when a query is started. | ||
* | ||
* @param {Query} query | ||
*/ | ||
queryStarted (query) { | ||
this.queries.add(query) | ||
} | ||
|
||
/** | ||
* Called when a query completes. | ||
* | ||
* @param {Query} query | ||
*/ | ||
queryCompleted (query) { | ||
this.queries.delete(query) | ||
} | ||
|
||
/** | ||
* Starts the query manager. | ||
*/ | ||
start () { | ||
this.running = true | ||
} | ||
|
||
/** | ||
* Stops all queries. | ||
*/ | ||
stop () { | ||
this.running = false | ||
for (const query of this.queries) { | ||
query.stop() | ||
} | ||
this.queries.clear() | ||
} | ||
} | ||
|
||
module.exports = QueryManager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters