fix user server future
This commit is contained in:
1 parent
1c4e1d84ea
commit
1afada528d
3 files changed
+13
-7
No files matched your search
@@ -18,8 +18,11 @@ where
|
|||||||
// We're doing this regardless so inputs get tracked, even if we drop the future before polling it
|
// We're doing this regardless so inputs get tracked, even if we drop the future before polling it
|
||||||
let user_fut = cb.call();
|
let user_fut = cb.call();
|
||||||
|
|
||||||
|
let currently_in_first_run = first_run.cloned();
|
||||||
|
|
||||||
// If this is the first run and we are on the web client, the data might be cached
|
// If this is the first run and we are on the web client, the data might be cached
|
||||||
if *first_run.peek() {
|
if currently_in_first_run {
|
||||||
|
tracing::info!("First run of use_server_future");
|
||||||
// This is no longer the first run
|
// This is no longer the first run
|
||||||
first_run.set(false);
|
first_run.set(false);
|
||||||
|
|
||||||
@@ -34,7 +37,7 @@ where
|
|||||||
|
|
||||||
// If this is the first run and we are on the server, cache the data
|
// If this is the first run and we are on the server, cache the data
|
||||||
#[cfg(feature = "ssr")]
|
#[cfg(feature = "ssr")]
|
||||||
if *first_run.peek() {
|
if currently_in_first_run {
|
||||||
let _ = crate::server_context::server_context().push_html_data(&out);
|
let _ = crate::server_context::server_context().push_html_data(&out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
#![allow(unused)]
|
#![allow(unused)]
|
||||||
|
use base64::Engine;
|
||||||
use std::{io::Cursor, sync::atomic::AtomicUsize};
|
use std::{io::Cursor, sync::atomic::AtomicUsize};
|
||||||
|
|
||||||
|
use base64::engine::general_purpose::STANDARD;
|
||||||
use serde::{de::DeserializeOwned, Serialize};
|
use serde::{de::DeserializeOwned, Serialize};
|
||||||
|
|
||||||
pub(crate) mod deserialize;
|
pub(crate) mod deserialize;
|
||||||
@@ -45,8 +46,9 @@ impl HTMLDataCursor {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let mut cursor = &self.data[current];
|
let mut cursor = &self.data[current];
|
||||||
|
let mut decoded = STANDARD.decode(cursor).unwrap();
|
||||||
self.index.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
|
self.index.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
|
||||||
match ciborium::from_reader(Cursor::new(cursor)) {
|
match ciborium::from_reader(Cursor::new(decoded)) {
|
||||||
Ok(x) => Some(x),
|
Ok(x) => Some(x),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
tracing::error!("Error deserializing data: {:?}", e);
|
tracing::error!("Error deserializing data: {:?}", e);
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ where
|
|||||||
|
|
||||||
let mut cb = use_callback(move || {
|
let mut cb = use_callback(move || {
|
||||||
// Create the user's task
|
// Create the user's task
|
||||||
|
#[allow(clippy::redundant_closure)]
|
||||||
let fut = rc.run_in(|| future());
|
let fut = rc.run_in(|| future());
|
||||||
|
|
||||||
// Spawn a wrapper task that polls the innner future and watch its dependencies
|
// Spawn a wrapper task that polls the innner future and watch its dependencies
|
||||||
@@ -136,20 +137,20 @@ impl<T> Resource<T> {
|
|||||||
/// Reading this does not subscribe to the future's state
|
/// Reading this does not subscribe to the future's state
|
||||||
pub fn finished(&self) -> bool {
|
pub fn finished(&self) -> bool {
|
||||||
matches!(
|
matches!(
|
||||||
self.state.peek().clone(),
|
*self.state.peek(),
|
||||||
UseResourceState::Ready | UseResourceState::Stopped
|
UseResourceState::Ready | UseResourceState::Stopped
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the current state of the future.
|
/// Get the current state of the future.
|
||||||
pub fn state(&self) -> ReadOnlySignal<UseResourceState> {
|
pub fn state(&self) -> ReadOnlySignal<UseResourceState> {
|
||||||
self.state.clone().into()
|
self.state.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Wait for this async memo to resolve, returning the inner signal value
|
/// Wait for this async memo to resolve, returning the inner signal value
|
||||||
/// If the value is pending, returns none and suspends the current component
|
/// If the value is pending, returns none and suspends the current component
|
||||||
pub fn suspend(&self) -> Option<ReadOnlySignal<T>> {
|
pub fn suspend(&self) -> Option<ReadOnlySignal<T>> {
|
||||||
let out = self.value.read().clone();
|
let out = self.value.cloned();
|
||||||
if out.is_none() {
|
if out.is_none() {
|
||||||
suspend();
|
suspend();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user