wip: rip out unsafe task engine
This commit is contained in:
1 parent
cda759c659
commit
c7d001cbb4
10 files changed
+144
-136
No files matched your search
@@ -10,5 +10,8 @@ pub use use_shared_state::*;
|
||||
mod usecoroutine;
|
||||
pub use usecoroutine::*;
|
||||
|
||||
mod usemodel;
|
||||
pub use usemodel::*;
|
||||
mod usefuture;
|
||||
pub use usefuture::*;
|
||||
|
||||
// mod usemodel;
|
||||
// pub use usemodel::*;
|
||||
@@ -1,10 +1,6 @@
|
||||
use dioxus_core::ScopeState;
|
||||
use std::future::Future;
|
||||
use std::{
|
||||
cell::{Cell, RefCell},
|
||||
pin::Pin,
|
||||
rc::Rc,
|
||||
};
|
||||
use std::{cell::Cell, pin::Pin, rc::Rc};
|
||||
/*
|
||||
|
||||
|
||||
@@ -24,8 +20,7 @@ pub fn use_coroutine<'a, F>(
|
||||
create_future: impl FnOnce() -> F,
|
||||
) -> CoroutineHandle<'a>
|
||||
where
|
||||
F: Future<Output = ()>,
|
||||
F: 'static,
|
||||
F: Future<Output = ()> + 'static,
|
||||
{
|
||||
cx.use_hook(
|
||||
move |_| State {
|
||||
@@ -35,11 +30,13 @@ where
|
||||
},
|
||||
|state| {
|
||||
let f = create_future();
|
||||
state.pending_fut.set(Some(Box::pin(f)));
|
||||
let id = cx.push_future(f);
|
||||
|
||||
if let Some(fut) = state.running_fut.as_mut() {
|
||||
cx.push_task(fut);
|
||||
}
|
||||
// state.pending_fut.set(Some(Box::pin(f)));
|
||||
|
||||
// if let Some(fut) = state.running_fut.as_mut() {
|
||||
// cx.push_future(fut);
|
||||
// }
|
||||
|
||||
// if let Some(fut) = state.running_fut.take() {
|
||||
// state.running.set(true);
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
use dioxus_core::{ScopeState, TaskId};
|
||||
use std::{cell::Cell, future::Future};
|
||||
|
||||
pub fn use_future<'a, T: 'static, F: Future<Output = T>>(
|
||||
cx: &'a ScopeState,
|
||||
f: impl FnOnce() -> F,
|
||||
) -> FutureHandle<'a, T> {
|
||||
cx.use_hook(
|
||||
|_| {
|
||||
//
|
||||
UseFutureInner {
|
||||
needs_regen: true,
|
||||
task: None,
|
||||
}
|
||||
},
|
||||
|_| {
|
||||
//
|
||||
FutureHandle {
|
||||
cx,
|
||||
value: Cell::new(None),
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
struct UseFutureInner {
|
||||
needs_regen: bool,
|
||||
task: Option<TaskId>,
|
||||
}
|
||||
|
||||
pub struct FutureHandle<'a, T> {
|
||||
cx: &'a ScopeState,
|
||||
value: Cell<Option<T>>,
|
||||
}
|
||||
Reference in new issue
Block a user