Skip to content

Commit

Permalink
Improve code readability
Browse files Browse the repository at this point in the history
  • Loading branch information
temeddix committed Jun 16, 2024
1 parent 3db2e4f commit fb3b03b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
3 changes: 2 additions & 1 deletion documentation/docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,14 @@ Define an async Rust function that runs forever, sending numbers to Dart every s
```rust title="native/hub/src/sample_functions.rs"
...
use crate::messages;
use std::time::Duration;
...
pub async fn stream_amazing_number() {
use messages::tutorial_resource::*;

let mut current_number: i32 = 1;
loop {
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
tokio::time::sleep(Duration::from_secs(1)).await;
MyAmazingNumber { current_number }.send_signal_to_dart(); // GENERATED
current_number += 1;
}
Expand Down
11 changes: 6 additions & 5 deletions flutter_ffi_plugin/example/native/hub/src/sample_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use crate::messages;
use crate::tokio;
use rinf::debug_print;
use std::time::Duration;
use tokio::sync::Mutex;

// Using the `cfg` macro enables conditional statement.
Expand Down Expand Up @@ -57,7 +58,7 @@ pub async fn stream_fractal() {
tokio::spawn(async move {
loop {
// Wait for 40 milliseconds on each frame
tokio::time::sleep(std::time::Duration::from_millis(40)).await;
tokio::time::sleep(Duration::from_millis(40)).await;
if sender.capacity() == 0 {
continue;
}
Expand Down Expand Up @@ -120,7 +121,7 @@ pub async fn run_debug_tests() {
return;
}

tokio::time::sleep(std::time::Duration::from_secs(1)).await;
tokio::time::sleep(Duration::from_secs(1)).await;
debug_print!("Starting debug tests.");

// Get the current time.
Expand All @@ -138,15 +139,15 @@ pub async fn run_debug_tests() {

// Test `tokio::join!` for futures.
let join_first = async {
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
tokio::time::sleep(Duration::from_secs(1)).await;
debug_print!("First future finished.");
};
let join_second = async {
tokio::time::sleep(std::time::Duration::from_secs(2)).await;
tokio::time::sleep(Duration::from_secs(2)).await;
debug_print!("Second future finished.");
};
let join_third = async {
tokio::time::sleep(std::time::Duration::from_secs(3)).await;
tokio::time::sleep(Duration::from_secs(3)).await;
debug_print!("Third future finished.");
};
tokio::join!(join_first, join_second, join_third);
Expand Down
6 changes: 3 additions & 3 deletions rust_crate/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ macro_rules! write_interface {
binary_pointer: *const u8,
binary_size: usize,
) {
let message_bytes =
unsafe { std::slice::from_raw_parts(message_pointer, message_size) };
let binary = unsafe { std::slice::from_raw_parts(binary_pointer, binary_size) };
use std::slice::from_raw_parts;
let message_bytes = unsafe { from_raw_parts(message_pointer, message_size) };
let binary = unsafe { from_raw_parts(binary_pointer, binary_size) };
messages::generated::handle_dart_signal(message_id, message_bytes, binary);
}

Expand Down

0 comments on commit fb3b03b

Please sign in to comment.