Skip to content

fix: ensure streaming queries stay open and can be closed - #317

Merged
gabor-boros merged 1 commit into
masterfrom
fix-streaming-cursor
Nov 16, 2026
Merged

gabor-boros merged 1 commit into
masterfrom
fix-streaming-cursor

Conversation

@gabor-boros

Copy link
Copy Markdown
Member

Reason for the change

Fixes #222

Description

Streaming queries such as between fails on every async driver.

Code examples

import asyncio
from datetime import datetime, timedelta, timezone

from rethinkdb import r


async def main() -> None:
    r.set_loop_type("asyncio")
    conn = await r.connect(host="localhost", port=28015, db="test")
    try:
        if "station" not in await r.table_list().run(conn):
            await r.table_create("station").run(conn)
            await r.table("station").index_create("DT_GEN").run(conn)
            await r.table("station").index_wait("DT_GEN").run(conn)

        now = datetime.now(timezone.utc)
        await r.table("station").insert(
            {
                "id": "reading-1",
                "DT_GEN": r.iso8601(now.isoformat()),
                "value": 42,
            }
        ).run(conn)

        lower = r.iso8601((now - timedelta(seconds=200)).isoformat())
        upper = r.iso8601((now + timedelta(seconds=1)).isoformat())
        cursor = await (
            r.table("station")
            .between(lower, upper, index="DT_GEN", left_bound="closed", right_bound="open")
            .run(conn)
        )
        async for row in cursor:
            print(row["id"], row["DT_GEN"], row["value"])
    finally:
        await conn.close()


if __name__ == "__main__":
    asyncio.run(main())

Checklist

References

N/A

Signed-off-by: Gabor Boros <gabor.brs@gmail.com>
@gabor-boros
gabor-boros merged commit a3ae56c into master Nov 16, 2026
13 checks passed
@github-actions github-actions Bot mentioned this pull request Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

On python 3.8 the query for 'between' in a table CANCEL TASK....

1 participant