pub struct ServerMultiAction<S>{ /* private fields */ }Expand description
A MultiAction that can be used to call a server function.
Implementations§
Methods from Deref<Target = MultiAction<S, Result<S::Output, S::Error>>>§
Sourcepub fn dispatch(&self, input: I)
pub fn dispatch(&self, input: I)
Calls the async function with a reference to the input type as its argument.
This can be called any number of times: each submission will be dispatched, running
concurrently, and its status can be checked via the
submissions() signal.
async fn send_new_todo_to_api(task: String) -> usize {
// do something...
// return a task id
42
}
let add_todo = MultiAction::new(|task: &String| {
// `task` is given as `&String` because its value is available in `input`
send_new_todo_to_api(task.clone())
});
let submissions = add_todo.submissions();
let pending_submissions = move || {
submissions.with(|subs| subs.iter().filter(|sub| sub.pending().get()).count())
};
add_todo.dispatch("Buy milk".to_string());
assert_eq!(submissions.with(Vec::len), 1);
assert_eq!(pending_submissions(), 1);
add_todo.dispatch("???".to_string());
add_todo.dispatch("Profit!!!".to_string());
assert_eq!(submissions.with(Vec::len), 3);
assert_eq!(pending_submissions(), 3);
// when submissions resolve, they are not removed from the set
// however, their `pending` signal is now `false`, and this can be used to filter them
assert_eq!(submissions.with(Vec::len), 3);
assert_eq!(pending_submissions(), 0);Sourcepub fn dispatch_sync(&self, value: O)
pub fn dispatch_sync(&self, value: O)
Synchronously adds a submission with the given value.
This takes the output value, rather than the input, because it is adding a result, not an input.
This can be useful for use cases like handling errors, where the error can already be known on the client side.
async fn send_new_todo_to_api(task: String) -> usize {
// do something...
// return a task id
42
}
let add_todo = MultiAction::new(|task: &String| {
// `task` is given as `&String` because its value is available in `input`
send_new_todo_to_api(task.clone())
});
let submissions = add_todo.submissions();
let pending_submissions = move || {
submissions.with(|subs| subs.iter().filter(|sub| sub.pending().get()).count())
};
add_todo.dispatch("Buy milk".to_string());
assert_eq!(submissions.with(Vec::len), 1);
assert_eq!(pending_submissions(), 1);
add_todo.dispatch_sync(42);
assert_eq!(submissions.with(Vec::len), 2);
assert_eq!(pending_submissions(), 1);Sourcepub fn submissions(&self) -> ReadSignal<Vec<ArcSubmission<I, O>>>
pub fn submissions(&self) -> ReadSignal<Vec<ArcSubmission<I, O>>>
The set of all submissions to this multi-action.
async fn send_new_todo_to_api(task: String) -> usize {
// do something...
// return a task id
42
}
let add_todo = MultiAction::new(|task: &String| {
// `task` is given as `&String` because its value is available in `input`
send_new_todo_to_api(task.clone())
});
let submissions = add_todo.submissions();
add_todo.dispatch("Buy milk".to_string());
add_todo.dispatch("???".to_string());
add_todo.dispatch("Profit!!!".to_string());
assert_eq!(submissions.with(Vec::len), 3);Sourcepub fn version(&self) -> RwSignal<usize>
pub fn version(&self) -> RwSignal<usize>
How many times an action has successfully resolved.
async fn send_new_todo_to_api(task: String) -> usize {
// do something...
// return a task id
42
}
let add_todo = MultiAction::new(|task: &String| {
// `task` is given as `&String` because its value is available in `input`
send_new_todo_to_api(task.clone())
});
let version = add_todo.version();
add_todo.dispatch("Buy milk".to_string());
add_todo.dispatch("???".to_string());
add_todo.dispatch("Profit!!!".to_string());
assert_eq!(version.get(), 0);
// when they've all resolved
assert_eq!(version.get(), 3);Trait Implementations§
Source§impl<S> Clone for ServerMultiAction<S>
impl<S> Clone for ServerMultiAction<S>
Source§impl<S> Default for ServerMultiAction<S>
impl<S> Default for ServerMultiAction<S>
Source§impl<S> DefinedAt for ServerMultiAction<S>
impl<S> DefinedAt for ServerMultiAction<S>
Source§fn defined_at(&self) -> Option<&'static Location<'static>>
fn defined_at(&self) -> Option<&'static Location<'static>>
Returns the location at which the signal was defined. This is usually simply
None in
release mode.Source§impl<S> Deref for ServerMultiAction<S>
impl<S> Deref for ServerMultiAction<S>
Source§impl<S> From<ServerMultiAction<S>> for MultiAction<S, Result<S::Output, S::Error>>
impl<S> From<ServerMultiAction<S>> for MultiAction<S, Result<S::Output, S::Error>>
Source§fn from(value: ServerMultiAction<S>) -> Self
fn from(value: ServerMultiAction<S>) -> Self
Converts to this type from the input type.
impl<S> Copy for ServerMultiAction<S>
Auto Trait Implementations§
impl<S> Freeze for ServerMultiAction<S>
impl<S> RefUnwindSafe for ServerMultiAction<S>
impl<S> Send for ServerMultiAction<S>
impl<S> Sync for ServerMultiAction<S>
impl<S> Unpin for ServerMultiAction<S>
impl<S> UnwindSafe for ServerMultiAction<S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> StorageAccess<T> for T
impl<T> StorageAccess<T> for T
Source§fn as_borrowed(&self) -> &T
fn as_borrowed(&self) -> &T
Borrows the value.
Source§fn into_taken(self) -> T
fn into_taken(self) -> T
Takes the value.