Skip to content

Add Observable and SynchronizedObserver utilities#46

Merged
Tyrrrz merged 5 commits intoprimefrom
copilot/add-observable-utilities
Apr 17, 2026
Merged

Add Observable and SynchronizedObserver utilities#46
Tyrrrz merged 5 commits intoprimefrom
copilot/add-observable-utilities

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 17, 2026

Ports Observable and SynchronizedObserver utility types from CliWrap into PowerKit.

New types

  • Observable<T>IObservable<T> implementation backed by a subscribe delegate.
  • Observable (static) — factory methods:
    • Create<T> — wraps a subscribe delegate into an observable.
    • CreateSynchronized<T> — same, but wraps the observer in SynchronizedObserver<T> before invoking the delegate, ensuring thread-safe delivery.
  • SynchronizedObserver<T>IObserver<T> decorator that serializes OnNext/OnError/OnCompleted calls via lock.

Both files are guarded with #if NET40_OR_GREATER || NETSTANDARD || NET since IObservable<T>/IObserver<T> don't exist in .NET 3.5.

Usage

var observable = Observable.CreateSynchronized<string>(observer =>
{
    // observer calls are automatically serialized across threads
    return Disposable.Create(() => { /* cleanup */ });
});

@Tyrrrz Tyrrrz added the enhancement New feature or request label Apr 17, 2026
@Tyrrrz Tyrrrz marked this pull request as ready for review April 17, 2026 12:37
Copilot AI review requested due to automatic review settings April 17, 2026 12:37
Comment thread PowerKit.Tests/ObservableTests.cs Outdated
Comment thread PowerKit.Tests/ObservableTests.cs Outdated
Comment thread PowerKit/Observable.cs Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Ports lightweight IObservable<T>/IObserver<T> utilities into PowerKit (aligned with the project’s existing “small internal building blocks” approach) and adds tests to validate subscription behavior and synchronized delivery across threads.

Changes:

  • Added Observable<T> + Observable factory helpers to create observables from a subscribe delegate.
  • Added SynchronizedObserver<T> to serialize observer callbacks via lock, and Observable.CreateSynchronized<T> to apply it automatically.
  • Added unit tests covering basic observable behavior and a multi-threaded delivery scenario.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
PowerKit/SynchronizedObserver.cs Adds an IObserver<T> decorator that serializes OnNext/OnError/OnCompleted calls.
PowerKit/Observable.cs Adds a minimal IObservable<T> implementation + factory helpers including synchronized creation.
PowerKit.Tests/ObservableTests.cs Adds coverage for Observable.Create, disposal propagation, and synchronized/thread-safe delivery.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread PowerKit.Tests/ObservableTests.cs Outdated
Comment thread PowerKit/SynchronizedObserver.cs Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 17, 2026

Codecov Report

❌ Patch coverage is 94.73684% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.35%. Comparing base (e1aaff9) to head (3473b18).
⚠️ Report is 4 commits behind head on prime.

Files with missing lines Patch % Lines
PowerKit/SynchronizedObserver.cs 71.42% 4 Missing ⚠️
PowerKit.Tests/ObservableTests.cs 97.91% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            prime      #46      +/-   ##
==========================================
- Coverage   94.36%   94.35%   -0.02%     
==========================================
  Files          82       87       +5     
  Lines        1740     1878     +138     
  Branches      141      152      +11     
==========================================
+ Hits         1642     1772     +130     
- Misses         72       77       +5     
- Partials       26       29       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/a292f88b-67bc-49ee-bc23-32d920986e9d

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants