Skip to content

Commit 8ae827d

Browse files
async example
1 parent 1c3f4d6 commit 8ae827d

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

examples/app/src-tauri/src/main.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ fn goodbye_world() -> impl Serialize + specta::Type {
2424
"Goodbye world :("
2525
}
2626

27+
#[tauri::command]
28+
#[specta::specta]
29+
async fn async_hello_world(my_name: String) -> String {
30+
format!("Hello, {my_name}!")
31+
}
32+
2733
#[tauri::command]
2834
#[specta::specta]
2935
fn has_error() -> Result<&'static str, i32> {
@@ -121,6 +127,7 @@ fn main() {
121127
.commands(tauri_specta::collect_commands![
122128
hello_world,
123129
goodbye_world,
130+
async_hello_world,
124131
has_error,
125132
nested::some_struct,
126133
generic::<tauri::Wry>,

examples/app/src/bindings-jsdoc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ async helloWorld(myName) {
2020
async goodbyeWorld() {
2121
return await TAURI_INVOKE("goodbye_world");
2222
},
23+
/**
24+
* @param { string } myName
25+
* @returns { Promise<string> }
26+
*/
27+
async asyncHelloWorld(myName) {
28+
return await TAURI_INVOKE("async_hello_world", { myName });
29+
},
2330
/**
2431
* @returns { Promise<Result<string, number>> }
2532
*/

examples/app/src/bindings.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ async helloWorld(myName: string) : Promise<string> {
1616
async goodbyeWorld() : Promise<string> {
1717
return await TAURI_INVOKE("goodbye_world");
1818
},
19+
async asyncHelloWorld(myName: string) : Promise<string> {
20+
return await TAURI_INVOKE("async_hello_world", { myName });
21+
},
1922
async hasError() : Promise<Result<string, number>> {
2023
try {
2124
return { status: "ok", data: await TAURI_INVOKE("has_error") };

0 commit comments

Comments
 (0)