1use crate::{AsyncValue, CancellationToken, Resource};
3use fusor::OwnerHandle;
4use std::future::Future;
5
6pub fn read<K, T, E, F>(
8 owner: &OwnerHandle,
9 key: impl Fn() -> K + 'static,
10 load: impl Fn(K, CancellationToken) -> F + 'static,
11) -> AsyncValue<K, T, E>
12where
13 K: Clone + PartialEq + 'static,
14 T: 'static,
15 E: std::fmt::Display + 'static,
16 F: Future<Output = Result<T, E>> + 'static,
17{
18 AsyncValue::new(owner, key, load, wasm_bindgen_futures::spawn_local)
19}
20
21pub fn resource<K, T, E, F>(
23 owner: &OwnerHandle,
24 key: impl Fn() -> Option<K> + 'static,
25 load: impl Fn(K, CancellationToken) -> F + 'static,
26) -> Resource<K, T, E>
27where
28 K: Clone + PartialEq + 'static,
29 T: 'static,
30 E: 'static,
31 F: Future<Output = Result<T, E>> + 'static,
32{
33 Resource::new(owner, key, load, wasm_bindgen_futures::spawn_local)
34}