Skip to content

[DO NOT MERGE] Add safe getOrResult, freshOrResult, getOrNull, freshOrNull extensions (#553) - #767

Open
binayshaw7777 wants to merge 2 commits into
MobileNativeFoundation:mainfrom
binayshaw7777:binay/feat-safe-get-fresh-extensions
Open

binayshaw7777 wants to merge 2 commits into
MobileNativeFoundation:mainfrom
binayshaw7777:binay/feat-safe-get-fresh-extensions

Conversation

@binayshaw7777

Copy link
Copy Markdown

Closes #553

Description

Calling store.get() or store.fresh() throws directly when the fetcher encounters an error or returns no data. This can cause unexpected crashes if callers forget try/catch wrappers.

This PR introduces idiomatic, safe convenience extension functions for both Store and MutableStore:

  • getOrResult(key: Key): Result<Output>
  • freshOrResult(key: Key): Result<Output>
  • getOrNull(key: Key): Output?
  • freshOrNull(key: Key): Output?

Coroutines structured concurrency is strictly maintained: CancellationException is rethrown rather than captured into Result.failure.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Test Plan

  • Added StoreExtensionsTest.kt covering:
    • getOrResult and getOrNull on success and failure
    • freshOrResult and freshOrNull on success and failure
    • CancellationException propagation
  • All local tests passing via ./gradlew :store:jvmTest.

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my change is effective
  • New and existing unit tests pass locally with my changes

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🆕 Triage

Development

Successfully merging this pull request may close these issues.

[Feature Request] getOrError and freshOrError

1 participant