Function woab::outside[][src]

pub async fn outside<T: 'static>(
    fut: impl Future<Output = T> + 'static
) -> Result<T, WakerPerished>
Expand description

Run a future outside the Actix runtime.

If operation that generate GTK signals are executed inside the Actix runtime, they’ll be queued to run later by the Actix event loop. This may be a problem if the signal is expecting an inhibit decision, because the handler will not be able to generate it before the signal returns. This may also be a problem for signals that use a context parameter (like draw), because by the time the handler is invoked the context will already expire. In such cases, the code that triggers the signal must run outside.

Note: Most GTK signals that have these requirements are already queued by GTK. This function was more useful before version 0.6 of WoAB , when signals were never queued by WoAB and all signals GTK handles immediately were required to run outside. Now it is not needed, but not deprecated either because the possibility of misbehaving custom signals cannot be ruled out.

Similar to spawn_outside, but waits for the future to finish and returns its result.

impl actix::Handler<woab::Signal> for WindowActor {
    type Result = woab::SignalResult;

    fn handle(&mut self, msg: woab::Signal, ctx: &mut Self::Context) -> Self::Result {
        Ok(match msg.name() {
            "remove_button_clicked" => {
                let container = self.widgets.some_container.clone();
                let widget = self.widgets.some_widget.clone();

                ctx.spawn(async move {
                    // BAD! This will panic at runtime:
                    container.remove(&widget);

                    // Use this instead:
                    woab::outside(async move {
                        container.remove(&widget)
                    }).await;
                }.into_actor(self));

                None
            }
            _ => msg.cant_handle()?
        })
    }
}