zioRefAtomSync<E, A> function
Creates an Atom from a Ref contained in a ZIO. It will throw an error if the Ref cannot be accessed synchronously.
Implementation
AtomWithParent<A, Atom<Ref<A>>> zioRefAtomSync<E, A>(EIO<E, Ref<A>> zio) =>
atomWithParent(
atom((get) {
try {
return get(runtimeAtom).runSyncOrThrow(zio);
} on Interrupted {
throw "zioRefAtomSync: Could not access Ref. Maybe a Layer has not been built yet?";
}
}),
(get, parent) {
final ref = get(parent);
get.onDispose(ref.stream.listen((a) {
get.setSelf(a);
}).cancel);
return ref.unsafeGet();
},
);