Skip to content

How do I emit signals asynchronously from a goroutine? #39

Answered by Splizard
TeddyDD asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks for reporting this use case, as you've mentioned, it makes perfect sense to use Go in this way.

There are some issues here, the Something field needs to be exported, you can tag it as gd:"something". This should fix the panic. There's still the possibility of race conditions here. On the Godot side, Emit isn't necessarily thread 'safe'. So to do this safely, the signal needs to be emitted through a deferred call that runs on the main thread.

What I'm going to do, is add a representation for this using channels. If you add a write only channel field to your class. This will be registered as a signal available in Godot. Then you can send to this from a goroutine.

I would avoid callin…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Splizard
Comment options

@TeddyDD
Comment options

Answer selected by Splizard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #36 on July 06, 2024 22:23.