Skip to content

Add optional ReactiveX adapter for device events#7

Draft
bruno-f-cruz wants to merge 2 commits into
refactor-unified-apifrom
feat-device-event-logic
Draft

Add optional ReactiveX adapter for device events#7
bruno-f-cruz wants to merge 2 commits into
refactor-unified-apifrom
feat-device-event-logic

Conversation

@bruno-f-cruz

@bruno-f-cruz bruno-f-cruz commented Jul 4, 2026

Copy link
Copy Markdown
Member

Leaving this as a draft as it is a bit opinionated, but since I had this convo with @Poofjunior and @glopesdev separately, just putting it on a PR for future reference. This is how I would like to handle events from devices :P

Summary

tldr: reactive framework rocks — this is the optional Rx layer on top of the push-subscription API.

The core push-subscription API (Device.subscribe, Device.subscribe_all, the dedicated event thread) has already landed on refactor-unified-api directly, since it doesn't need ReactiveX. This PR is now scoped to just the optional Rx adapter on top of it.

What changed

  • Optional Rx adapter (harp.device.rx)observe(device, register) / observe_all(device) return hot, ref-counted (ops.share) Observables backed by a single underlying Device.subscribe/subscribe_all call. Gated behind the harp-device[rx] extra; importing the module without reactivex raises a clear ImportError. If I had it my way, we would only have this, but for now leaving it optional.
  • Examplescripts/event_monitor.py shows the Rx adapter alongside the plain subscribe_all API on a live device (COM3). (A non-Rx-only version of this example also lives at docs/examples/subscribing_to_events/.)

Notes

  • observe/observe_all emit on the device's shared event thread — use ops.observe_on(scheduler) to move heavy downstream work off it.

@bruno-f-cruz
bruno-f-cruz marked this pull request as draft July 4, 2026 02:51
@bruno-f-cruz
bruno-f-cruz force-pushed the feat-device-event-logic branch from eb7bb8b to 6863093 Compare July 17, 2026 20:20
@bruno-f-cruz bruno-f-cruz changed the title Add observer/observable pattern to device Add optional ReactiveX adapter for device events Jul 17, 2026
@harp-tech harp-tech deleted a comment from github-actions Bot Jul 17, 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.

1 participant