Skip to content

Add more realistic godot::task::spawn example#1581

Merged
Bromeon merged 1 commit into
godot-rust:masterfrom
bitterepic:master
May 9, 2026
Merged

Add more realistic godot::task::spawn example#1581
Bromeon merged 1 commit into
godot-rust:masterfrom
bitterepic:master

Conversation

@bitterepic

Copy link
Copy Markdown
Contributor

This is a small PR to try to make the example for godot::task::spawn more applicable for standard use cases.

@Bromeon Bromeon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution!

Commented on some grammar/clarity issues. You can apply them inline on the web, please make sure the PR eventually is one commit.

Please also fix CI -- you can run ./check.sh locally to catch a lot of issues 🙂

Comment thread godot-core/src/task/async_runtime.rs Outdated
Comment thread godot-core/src/task/async_runtime.rs Outdated
Comment thread godot-core/src/task/async_runtime.rs Outdated
Comment thread godot-core/src/task/async_runtime.rs Outdated
Comment thread godot-core/src/task/async_runtime.rs Outdated
Comment thread godot-core/src/task/async_runtime.rs Outdated
Comment on lines +62 to +67
/// self.bind()
/// .get_node_as::<Player>("Player")
/// .signals()
/// .hit()
/// .builder()
/// .connect_other_gd(self, Self::show_messages);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is .builder() necessary here? Can you not just call TypedSignal::connect_other() directly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check. I need to verify everything I'm saying before converting this draft to a PR.

@bitterepic bitterepic May 3, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.bind().get_node_as::<Player>("Player").signals().hit().connect_other() failed in compilation with a complaint of the types not matching.

type mismatch in function arguments
     │    expected function signature `for<'a> fn(&'a mut game::Game, godot::prelude::Gd<_>) -> _`
     │       found function signature `fn(godot::prelude::Gd<game::Game>, godot::prelude::Gd<_>) -> _`

Connecting this signal is one of the reasons why it took me so long to fit together a future workflow.

Comment thread godot-core/src/task/async_runtime.rs
Comment thread godot-core/src/task/async_runtime.rs Outdated
Comment thread godot-core/src/task/async_runtime.rs
@Bromeon Bromeon added documentation Improvements or additions to documentation c: async Everything related to async tasks/signals labels May 1, 2026
@GodotRust

Copy link
Copy Markdown

API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-1581

@bitterepic

Copy link
Copy Markdown
Contributor Author

Thanks for your contribution!

Commented on some grammar/clarity issues. You can apply them inline on the web, please make sure the PR eventually is one commit.

Please also fix CI -- you can run ./check.sh locally to catch a lot of issues 🙂

Thank you for the early deep feedback! (I applied all of the changes.) I think you did more thank you need at this step, but I definitely appreciate it. I'll leave another comment when this is closer to being convertible from a draft to a real PR. I want to make sure I am using your time well.

@bitterepic

bitterepic commented May 2, 2026

Copy link
Copy Markdown
Contributor Author

@Bromeon I made some good distance. I'm seeing an issue where create_timer doesn't exist when compiled from the docs but it works in a real project.

---- godot-core/src/task/async_runtime.rs - task::async_runtime::spawn (line 47) stdout ----
error[E0599]: no method named `create_timer` found for struct `godot::prelude::Gd<SceneTree>` in the current scope
  --> godot-core/src/task/async_runtime.rs:73:44
   |
73 |         let timer = self.base().get_tree().create_timer(duration);
   |                                            ^^^^^^^^^^^^ method not found in `godot::prelude::Gd<SceneTree>`

error: aborting due to 1 previous error

I'll look into this more tomorrow and I think the CI will pass. If you have an obvious idea why this is failing it would help a ton. It looks like not all of the code from godot is available in the compiled docs examples?

@bitterepic

Copy link
Copy Markdown
Contributor Author

@Bromeon I see that some features are turned off to make the doc tests faster. It is possible to remove this here and move it to something like the Rust Godot Book? Or is it better to tweak the feature config once I find it? Do you have input?

@bitterepic

Copy link
Copy Markdown
Contributor Author

API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-1581

Love this.

@Bromeon

Bromeon commented May 3, 2026

Copy link
Copy Markdown
Member

I see that some features are turned off to make the doc tests faster. It is possible to remove this here

Not really, the CI is fixed and I'd rather not make it slower. But you can run tests locally, either through the check.sh script, or with direct cargo check/test commands.

and move it to something like the Rust Godot Book?

Not sure how this relates to the book?

@bitterepic

Copy link
Copy Markdown
Contributor Author

I see that some features are turned off to make the doc tests faster. It is possible to remove this here

Not really, the CI is fixed and I'd rather not make it slower. But you can run tests locally, either through the check.sh script, or with direct cargo check/test commands.

I'm still new to this... but I'm guessing that there is a way to make the tests ignore lines while still keeping in the documentation. I'll give this a try.

and move it to something like the Rust Godot Book?

Not sure how this relates to the book?

I made a POC PR on the book's repository. Please take a look and I think you will better understand what I'm thinking.

When you have time, please give me feedback on what is the preferred direction.

@bitterepic

Copy link
Copy Markdown
Contributor Author

The Ci now passes and I have squashed my commits. I'll migrate this PR out of draft status.

スクリーンショット 2026-05-07 12 46 58

@bitterepic
bitterepic force-pushed the master branch 2 times, most recently from 74e14dd to 7330133 Compare May 7, 2026 04:11
@bitterepic
bitterepic marked this pull request as ready for review May 7, 2026 04:13
Co-authored-by: Jan Haller <bromeon@gmail.com>
@Bromeon Bromeon changed the title Add a more real godot::task::spawn example to the documentation Add more realistic godot::task::spawn example May 9, 2026
@Bromeon

Bromeon commented May 9, 2026

Copy link
Copy Markdown
Member

I removed the fn ready(&mut self) since it doesn't contribute to the concept being demonstrated (async) while adding quite a bit of noise.

Also re-enabled the code block (it was ignored, causing a warning in docs). Since SceneTreeTimer is not in minimal codegen, this needed some... creativity 😬 but we've done this in other places, and it's better to have only part of the example mocked than the whole one not compiled.

Thanks for your contribution!

@Bromeon
Bromeon enabled auto-merge May 9, 2026 13:22
@Bromeon
Bromeon added this pull request to the merge queue May 9, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 9, 2026
@Bromeon
Bromeon added this pull request to the merge queue May 9, 2026
Merged via the queue into godot-rust:master with commit 4c724da May 9, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c: async Everything related to async tasks/signals documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants