Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(RefSubject): get/unsafeGet(Exit) #47

Merged
merged 2 commits into from
Feb 20, 2024

Conversation

TylorS
Copy link
Owner

@TylorS TylorS commented Feb 19, 2024

RefSubject.get

  • Works on RefSubject, Computed, and Filtered, returning an Effect for their current values.

RefSubject.unsafeGetExit

The unsafeGet method has been added to each interface for RefSubject, Computed, and Filtered, and this function just defers to their implementations.

It truly is UNSAFE, and WILL throw if a value has not been initialized. For RefSubject, only RefSubject.of(value), has a value directly after construction, all others will still require being initialized in an Effect runtime before being called, or else it will throw a Cause.NoSuchElementException. For more custom use cases, RefSubject.unsafeMake accepts an initialValue option as well.

There are RefSubject.tagged and RefSubject.fromTag which will immediately throw with an error message that they do not support unsafeGet at all because they require the Effect context by definition. If this is necessary, use RefSubject.provide to provide those services, and use Effect.runSync(RefSubject.get(ref))

For Computed and Filtered, because they both require Effectful computations, they always require an initialization before being able to sucessfully call unsafeGetExit

RefSubject.unsafeGet

This is implemented as just Effect.runSync(RefSubject.unsafeGetExit(ref)), such that any Exit failures are thrown with their Causes in the same way that Effect would.


Possibly closes #46

@TylorS TylorS merged commit 212b234 into development Feb 20, 2024
4 checks passed
@github-actions github-actions bot mentioned this pull request Feb 20, 2024
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.

Missing RefSubject.get and RefSubject.unsafeGet
1 participant