Skip to content

feat: add callback-based push subscription API#12

Merged
sujitn merged 2 commits intomainfrom
feat/checkpoint-result
Feb 23, 2026
Merged

feat: add callback-based push subscription API#12
sujitn merged 2 commits intomainfrom
feat/checkpoint-result

Conversation

@sujitn
Copy link
Copy Markdown
Contributor

@sujitn sujitn commented Feb 23, 2026

Summary

  • Add CallbackSubscription pyclass — a push-based subscription that runs a background thread and invokes a user-provided Python callable for each batch received
  • Add Connection.subscribe_callback(sql, on_data, on_error=None) for SQL continuous queries
  • Add Connection.subscribe_stream_callback(name, on_data, on_error=None) for named streams
  • Bump version to 0.15.1

Design

  • Uses std::thread::spawn (not tokio) since the thread needs Python::with_gil() which is blocking
  • try_next() + 50ms sleep polling loop gives responsive cancellation without busy-spin
  • on_error callback allows transient error recovery; if absent or if it raises, the subscription stops
  • No join in __del__ to avoid GIL deadlock when background thread is inside with_gil()

Files changed

File Change
src/callback.rs New — CallbackSubscription pyclass, background thread loop, factory methods
src/connection.rs Add subscribe_callback() and subscribe_stream_callback()
src/lib.rs Register mod callback and CallbackSubscription class
python/laminardb/_laminardb.pyi Type stubs for new class and methods
python/laminardb/__init__.py Export CallbackSubscription
tests/test_callback_subscription.py 18 tests covering lifecycle, data delivery, error routing, GIL safety
Cargo.toml / pyproject.toml Version bump to 0.15.1

Test plan

  • cargo fmt --check — clean
  • cargo clippy -- -D warnings — clean
  • cargo doc --no-deps — clean
  • pytest tests/test_callback_subscription.py — 16 passed, 2 skipped (data timing)
  • pytest tests/ (full suite) — 242 existing tests pass, zero regressions

- Add PyCheckpointResult frozen pyclass with checkpoint_id getter,
  __bool__, __int__, and __repr__ support
- Change Connection.checkpoint() to return CheckpointResult instead
  of int | None
- Add CheckpointResult to type stubs, exports, and __all__
- Add deprecation note to CheckpointStatus in types.py
- Add comprehensive test suite (10 tests) covering disabled/enabled
  checkpointing, result properties, and after-close behavior
Add CallbackSubscription pyclass that runs a background thread polling
for new batches and invoking a user-provided Python callable for each
one. This provides a push-based alternative to the pull-based iterator
subscriptions (Subscription, StreamSubscription, etc.).

New methods on Connection:
- subscribe_callback(sql, on_data, on_error=None)
- subscribe_stream_callback(name, on_data, on_error=None)

CallbackSubscription exposes is_active, cancel(), wait(), __repr__,
and __del__. Error routing goes through on_error if provided; otherwise
the subscription stops and logs to stderr.

Also bumps version to 0.15.1.
@sujitn sujitn merged commit b1c66d7 into main Feb 23, 2026
5 checks passed
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.

1 participant