-
Couldn't load subscription status.
- Fork 326
Close cursor from the outside #526
-
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?
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment 1 reply
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
-
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.
Beta Was this translation helpful? Give feedback.