Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/2-3-5-41/godot_tokio
A basic implementation of the Tokio runtime for use in Godot 4.1.
https://github.com/2-3-5-41/godot_tokio
Last synced: 23 days ago
JSON representation
A basic implementation of the Tokio runtime for use in Godot 4.1.
- Host: GitHub
- URL: https://github.com/2-3-5-41/godot_tokio
- Owner: 2-3-5-41
- Created: 2023-08-07T19:03:39.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-11-30T17:39:36.000Z (23 days ago)
- Last Synced: 2024-11-30T17:49:25.724Z (23 days ago)
- Language: Rust
- Size: 4.88 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# godot_tokio
This was made to prevent re-typing out the boilerplate for creating a tokio runtime godot object.
## Example Use snippets
You can simply create an engine singleton that makes the Tokio runtime accessable by all godot objects.
```rs
#[gdextension]
unsafe impl ExtensionLibrary for Metaphy {
fn on_level_init(level: InitLevel) {
match level {
InitLevel::Scene => {
Engine::singleton().register_singleton(AsyncRuntime::SINGLETON, &AsyncRuntime::new_alloc());
}
_ => (),
}
}fn on_level_deinit(level: InitLevel) {
match level {
InitLevel::Scene => {
let mut engine = Engine::singleton();if let Some(async_singleton) = engine.get_singleton(AsyncRuntime::SINGLETON) {
engine.unregister_singleton(AsyncRuntime::SINGLETON);
async_singleton.free();
} else {
godot_warn!(
"Failed to find & free singleton -> {}",
AsyncRuntime::SINGLETON
);
}
}
_ => (),
}
}
}
```Then you can access the runtime/singleton like other non-builtin engine singletons.
```rs
let tokio = match Engine::singleton().get_singleton(AsyncRuntime::SINGLETON) {
Some(object) => object.cast::(),
None => return godot_error!("Failed to get singleton -> {}", AsyncRuntime::SINGLETON),
};
```