-
-
Notifications
You must be signed in to change notification settings - Fork 224
Emit signals async #1120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I haven’t used let mut self_gd = self.to_gd();
let _task_handle = godot::task::spawn(async move {
self_gd.signals().damage_taken().emit(amount);
}); |
If you're just looking for a solution: https://github.com/Houtamelo/gdext_coroutines node.start_async_task(
async {
smol::Timer::after(Duration::from_secs(10)).await;
some_node.signals().damage_taken().emit(amount);
}); |
@ValorZard to clarify, you want to spawn an async task and then emit a signal inside that task? If yes, then the solution @ColinWttt wrote should work. (Note: |
The main problem is that these solutions only work with godot tasks. I'm doing stuff with tokio, and i can't do that inside of tokio::spawn() |
I see. This stems from the fact that
|
You might be interested in Not sure if |
(For context this is what I've been up to: https://github.com/ValorZard/godot-iroh-gossip-example ) Basically, I've been trying to integrate this into godot: https://www.iroh.computer/docs/examples/gossip-chat |
I don't think there is anything actionable in this issue. |
yeah seems pretty clear signals can never be send sync cuz the gd smart pointer cant be (for now anyways) |
Signals in Godot-rust are like 90% perfect to being perfect.
There’s already been lots of prior work done on async signals, but they are all around connecting them and receiving them.
There doesn’t seem to be much work done on EMITTING signals async.
The biggest problem I can think of is that usually &self is not send/sync, since Gd isn’t suited for multi threading. As such, there’s basically no way to spawn an async task within a function that emits a signal.
For example, this does not work (assume I am using https://github.com/2-3-5-41/godot_tokio )
I’ll be honest - not totally sure how to fix this. Maybe allow to clone a signal?
For the record: the current way to do this is to run your async tasks in the background, and poll on process() using channels. Once you receive something in the channel, you can emit a signal to let the other nodes that something happened. This is FINE, but it’s unwieldy and doesn’t feel very Godot.
The text was updated successfully, but these errors were encountered: