I have a method that is going to take a while to finish to run from my _process(delta) method. Since I don't want this to lag the main thread, I thought I could move the logic into a separate thread, but it's not working.

Basically, when the user changes a parameter on a field, a flag is set indicating the the component needs and update. The _process method checks to see if the flag is set and if it is, if a thread is already running to update the component. If no thread is running, one is created and given my long method to run.

I then want to wait for the thread to finish so I can take the result and use it in my component. I thought I could do this by calling await thread.wait_to_finish(), but that's just causing the main thread to block.

What's the right way to wait for a thread to complete?

var thread_build_mesh:Thread
var count:int = 0

func _process(delta):
	if flag_update_mesh:
		print("flag_update_mesh %d" % count)
		count += 1
		if !thread_build_mesh:
			print("start thread")
			thread_build_mesh = Thread.new()
			thread_build_mesh.start(build_mesh)
			await thread_build_mesh.wait_to_finish()
			thread_build_mesh = null
			print("end thread")
			
			flag_update_mesh = false
kitfox changed the title to How do I wait for a thread to finish without blocking? .

I guess you could just store a reference to your thread(s) and use thread.is_alive. From its description it seems to be exactly what you are looking for.
Check every frame if the thread is still alive. Once it's done, call wait_to_finish and do the things you still have to do on main thread.

@Armynator That sounds unnecessary expensive. Just have the thread signal the main thread when it has finished (e.g. with call_deferred) and have the main thread then end the 2nd thread.