Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Close cursor from the outside #526

Unanswered
mattbishop asked this question in Q&A
Discussion options

I am using cursors to page data, and I understand from the docs that the cursor can be closed early by breaking from the for...await loop or returning sql.END from the callback. In my case, I a signal outside the consumer of the cursor that indicates I need to close it.

Is there a way to close a cursor after it has started iterating, but from outside the consumption loop?

You must be logged in to vote

Replies: 1 comment 1 reply

Comment options

In reading further, AsyncIterator has two optional methods--return() and throw(err) where one can signal an early termination with "normal" circumstances (return()) or with an error (throw(err)). In debugging the cursor AsyncIterator, I do not see either of these methods available to cancel the cursor.

You must be logged in to vote
1 reply
Comment options

I figured it out. The cursor() object is the Iterable, but if one calls cursor[Symbol.asyncIterator]() to get the iterator, it is the actual AsyncIterator. That object has return() which one can use to cancel the cursor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /