multiple fullstack nits/cleanups before release (#4852)
* feat: `:arg` syntax for serverfn * add better decode/encode verify message * allow catch-all query args * add rebind * implement websocket frames for `Streaming` * fix lazy init * wip... serverfnstate * wip... * wip: serverfns require Send/Sync, let's fix that * wip... * small cleanup * fix hang by actually spawning the tokio task * clippy * fix parameter catchall binding * fix lychee * doc tests
This commit is contained in:
1 parent
43373f0be7
commit
5559e463c8
27 files changed
+1395
-1097
No files matched your search
@@ -88,6 +88,20 @@ impl<T: Send + Sync + 'static> Lazy<T> {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Get a reference to the value of the `Lazy` instance. This will block the current thread if the
|
||||
/// value is not yet initialized.
|
||||
pub fn get(&self) -> &T {
|
||||
if self.constructor.is_none() {
|
||||
return self.value.get().expect("Lazy value is not initialized. Make sure to call `initialize` before dereferencing.");
|
||||
};
|
||||
|
||||
if self.value.get().is_none() {
|
||||
self.initialize().expect("Failed to initialize lazy value");
|
||||
}
|
||||
|
||||
self.value.get().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Send + Sync + 'static> Default for Lazy<T> {
|
||||
@@ -100,15 +114,13 @@ impl<T: Send + Sync + 'static> std::ops::Deref for Lazy<T> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
if self.constructor.is_none() {
|
||||
return self.value.get().expect("Lazy value is not initialized. Make sure to call `initialize` before dereferencing.");
|
||||
};
|
||||
self.get()
|
||||
}
|
||||
}
|
||||
|
||||
if self.value.get().is_none() {
|
||||
self.initialize().expect("Failed to initialize lazy value");
|
||||
}
|
||||
|
||||
self.value.get().unwrap()
|
||||
impl<T: std::fmt::Debug + Send + Sync + 'static> std::fmt::Debug for Lazy<T> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("Lazy").field("value", self.get()).finish()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,10 +141,16 @@ where
|
||||
{
|
||||
let ptr: F = unsafe { std::mem::zeroed() };
|
||||
let fut = ptr();
|
||||
let rt = tokio::runtime::Handle::current();
|
||||
return std::thread::spawn(move || rt.block_on(fut).map_err(|e| e.into()))
|
||||
.join()
|
||||
.unwrap();
|
||||
return std::thread::spawn(move || {
|
||||
tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.unwrap()
|
||||
.block_on(fut)
|
||||
.map_err(|e| e.into())
|
||||
})
|
||||
.join()
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
// todo: technically we can support constructors in wasm with the same tricks inventory uses with `__wasm_call_ctors`
|
||||
|
||||
Reference in new issue
Block a user