-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
query cancel #1392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
query cancel #1392
Changes from 1 commit
5810fbb
b1f5aa7
d50159c
63b6ad9
b76ca42
039b5ba
cb3d4ae
dee5a59
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict' | ||
var helper = require('./test-helper') | ||
var Query = helper.pg.Query | ||
|
||
// before running this test make sure you run the script create-test-tables | ||
test('simple query interface', function () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test doesn’t accept a Queries spliced out of the queue should probably reject/emit an error like they would if cancelled while running. Then this test can use the promise API and:
|
||
var client = helper.client() | ||
client.on('drain', client.end.bind(client)) | ||
|
||
var query3 = client.query(new Query('select pg_sleep(3) as sleep3')) | ||
query3.on('row', function (row, result) { | ||
assert(true) | ||
}) | ||
|
||
var query5 = client.query(new Query('select pg_sleep(5) as sleep5')) | ||
client.cancel(query5); | ||
query5.on('row', function (row, result) { | ||
assert(false) | ||
}) | ||
|
||
var query7 = client.query(new Query('select pg_sleep(7) as sleep7')) | ||
client.cancel(query7); | ||
query7.on('row', function (row, result) { | ||
assert(false) | ||
}) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn’t be added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need a reference to the query to be able to cancel it later. Is this breaking something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it was removed intentionally and doesn’t work with promises. I’m not sure what the right fix is, though… requiring the
Query
object to be passed explicitly like in the tests? Or a separate method?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My idea was that if you want to cancel a request, you don't use the promise api. Most of users don't cancel queries, the few people who need to cancel will have to use the callback api. That seemed to me to be the best tradeoff.
In my application I have written a wrapper around the callback api to use promises. Cancelable queries resolves with something like:
But this is more complex for users; the cancelable queries api become different from the "normal" queries; and maybe it's not the pg responsibility to do this kind of things (too high level?). And the wrapper itself needs to keep references to query...
Do you remember why returning the query was removed?