mirror of
https://github.com/yewstack/yew.git
synced 2025-12-08 21:26:25 +00:00
parent
51238fb0e3
commit
889c6ba74e
@ -402,13 +402,11 @@ mod feat_io {
|
|||||||
use crate::io_coop::spawn_local;
|
use crate::io_coop::spawn_local;
|
||||||
|
|
||||||
impl<COMP: BaseComponent> Scope<COMP> {
|
impl<COMP: BaseComponent> Scope<COMP> {
|
||||||
/// This method creates a [`Callback`] which returns a Future which
|
/// This method creates a [`Callback`] which, when emitted, asynchronously awaits the
|
||||||
/// returns a message to be sent back to the component's event
|
/// message returned from the passed function before sending it to the linked component.
|
||||||
/// loop.
|
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
/// If the future panics, then the promise will not resolve, and
|
/// If the future panics, then the promise will not resolve, and will leak.
|
||||||
/// will leak.
|
|
||||||
pub fn callback_future<FN, FU, IN, M>(&self, function: FN) -> Callback<IN>
|
pub fn callback_future<FN, FU, IN, M>(&self, function: FN) -> Callback<IN>
|
||||||
where
|
where
|
||||||
M: Into<COMP::Message>,
|
M: Into<COMP::Message>,
|
||||||
@ -425,8 +423,8 @@ mod feat_io {
|
|||||||
closure.into()
|
closure.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This method processes a Future that returns a message and sends it back to the component's
|
/// This method asynchronously awaits a [Future] that returns a message and sends it
|
||||||
/// loop.
|
/// to the linked component.
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
/// If the future panics, then the promise will not resolve, and will leak.
|
/// If the future panics, then the promise will not resolve, and will leak.
|
||||||
@ -443,17 +441,19 @@ mod feat_io {
|
|||||||
spawn_local(js_future);
|
spawn_local(js_future);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Registers a Future that resolves to multiple messages.
|
/// Asynchronously send a batch of messages to a component. This asynchronously awaits the
|
||||||
|
/// passed [Future], before sending the message batch to the linked component.
|
||||||
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
/// If the future panics, then the promise will not resolve, and will leak.
|
/// If the future panics, then the promise will not resolve, and will leak.
|
||||||
pub fn send_future_batch<F>(&self, future: F)
|
pub fn send_future_batch<F>(&self, future: F)
|
||||||
where
|
where
|
||||||
F: Future<Output = Vec<COMP::Message>> + 'static,
|
F: Future + 'static,
|
||||||
|
F::Output: SendAsMessage<COMP>,
|
||||||
{
|
{
|
||||||
let link = self.clone();
|
let link = self.clone();
|
||||||
let js_future = async move {
|
let js_future = async move {
|
||||||
let messages: Vec<COMP::Message> = future.await;
|
future.await.send(&link);
|
||||||
link.send_message_batch(messages);
|
|
||||||
};
|
};
|
||||||
spawn_local(js_future);
|
spawn_local(js_future);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user