-
Hi there. I'm new to Rust ecosystem in general and to use crate::messages::dialogue::DialogueRequest;
pub async fn test_receiver(number: i8) {
let mut receiver = DialogueRequest::get_dart_signal_receiver();
println!("Test receiver number is {}", number);
while let Some(_dart_signal) = receiver.recv().await {
println!("Test receiver number is {}", number + 100);
}
}
#[cfg(test)]
mod tests {
use std::{cell::RefCell, sync::Mutex};
use crate::messages::dialogue::DIALOGUE_REQUEST_SENDER;
use super::*;
use tokio_with_wasm::tokio;
#[tokio::test]
async fn test_receive_character_creation_change() {
tokio::spawn(test_receiver(1));
tokio::time::sleep(tokio::time::Duration::from_millis(10)).await;
let binding = DIALOGUE_REQUEST_SENDER
.get_or_init(|| Mutex::new(RefCell::new(None)))
.lock()
.unwrap();
let binding = binding.borrow();
let sender = binding.as_ref().unwrap();
if let Ok(_result) = sender
.send(rinf::DartSignal::<DialogueRequest> {
message: DialogueRequest {},
blob: None,
})
.await
{
println!("Sent dialogue request");
}
}
} And here is what is in the successes:
---- receivers::test_receiver::tests::test_receive_character_creation_change stdout ----
Test receiver number is 1
Sent dialogue request As you can see, the sender The second problem is sending messages from Rust side: use crate::messages::{dialogue::DialogueRequest, scene::CurrentSceneChange};
pub async fn test_sender() {
CurrentSceneChange { scene: 0 }.send_signal_to_dart(None);
}
#[cfg(test)]
mod tests {
use super::*;
use tokio_with_wasm::tokio;
#[tokio::test]
async fn test_test_sender() {
test_sender().await;
}
} This test panics with this stack trace: ---- receivers::test_receiver::tests::test_test_sender stdout ----
thread 'receivers::test_receiver::tests::test_test_sender' panicked at /Users/tharin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rinf-6.7.0/src/interface_os.rs:30:35:
called `Option::unwrap()` on a `None` value
stack backtrace:
0: rust_begin_unwind
at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/std/src/panicking.rs:647:5
1: core::panicking::panic_fmt
at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/panicking.rs:72:14
2: core::panicking::panic
at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/panicking.rs:144:5
3: core::option::unwrap_failed
at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/option.rs:1978:5
4: core::option::Option<T>::unwrap
at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/option.rs:931:21
5: rinf::interface_os::send_rust_signal_extern
at /Users/tharin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rinf-6.7.0/src/interface_os.rs:30:16
6: rinf::interface::send_rust_signal
at /Users/tharin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rinf-6.7.0/src/interface.rs:24:5
7: hub::messages::scene::CurrentSceneChange::send_signal_to_dart
at ./src/messages/scene.rs:95:9
8: hub::receivers::test_receiver::test_sender::{{closure}}
at ./src/receivers/test_receiver.rs:14:5
9: hub::receivers::test_receiver::tests::test_test_sender::{{closure}}
at ./src/receivers/test_receiver.rs:51:23
10: <core::pin::Pin<P> as core::future::future::Future>::poll
at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/future/future.rs:124:9
11: <core::pin::Pin<P> as core::future::future::Future>::poll
at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/future/future.rs:124:9
12: tokio::runtime::scheduler::current_thread::CoreGuard::block_on::{{closure}}::{{closure}}::{{closure}}
at /Users/tharin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/scheduler/current_thread/mod.rs:659:57
13: tokio::runtime::coop::with_budget
at /Users/tharin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/coop.rs:107:5
14: tokio::runtime::coop::budget
at /Users/tharin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/coop.rs:73:5
15: tokio::runtime::scheduler::current_thread::CoreGuard::block_on::{{closure}}::{{closure}}
at /Users/tharin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/scheduler/current_thread/mod.rs:659:25
16: tokio::runtime::scheduler::current_thread::Context::enter
at /Users/tharin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/scheduler/current_thread/mod.rs:404:19
17: tokio::runtime::scheduler::current_thread::CoreGuard::block_on::{{closure}}
at /Users/tharin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/scheduler/current_thread/mod.rs:658:36
18: tokio::runtime::scheduler::current_thread::CoreGuard::enter::{{closure}}
at /Users/tharin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/scheduler/current_thread/mod.rs:737:68
19: tokio::runtime::context::scoped::Scoped<T>::set
at /Users/tharin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/context/scoped.rs:40:9
20: tokio::runtime::context::set_scheduler::{{closure}}
at /Users/tharin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/context.rs:176:26
21: std::thread::local::LocalKey<T>::try_with
at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/std/src/thread/local.rs:286:16
22: std::thread::local::LocalKey<T>::with
at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/std/src/thread/local.rs:262:9
23: tokio::runtime::context::set_scheduler
at /Users/tharin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/context.rs:176:9
24: tokio::runtime::scheduler::current_thread::CoreGuard::enter
at /Users/tharin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/scheduler/current_thread/mod.rs:737:27
25: tokio::runtime::scheduler::current_thread::CoreGuard::block_on
at /Users/tharin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/scheduler/current_thread/mod.rs:646:19
26: tokio::runtime::scheduler::current_thread::CurrentThread::block_on::{{closure}}
at /Users/tharin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/scheduler/current_thread/mod.rs:175:28
27: tokio::runtime::context::runtime::enter_runtime
at /Users/tharin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/context/runtime.rs:65:16
28: tokio::runtime::scheduler::current_thread::CurrentThread::block_on
at /Users/tharin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/scheduler/current_thread/mod.rs:167:9
29: tokio::runtime::runtime::Runtime::block_on
at /Users/tharin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/runtime.rs:349:47
30: hub::receivers::test_receiver::tests::test_test_sender
at ./src/receivers/test_receiver.rs:51:9
31: hub::receivers::test_receiver::tests::test_test_sender::{{closure}}
at ./src/receivers/test_receiver.rs:50:32
32: core::ops::function::FnOnce::call_once
at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/ops/function.rs:250:5
33: core::ops::function::FnOnce::call_once
at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. As you can see from the line 5 of the stacktrace, Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi @TheTharin :) For the first problem, I suggest you to sleep for some time after sending the signal so that use crate::messages::dialogue::DialogueRequest;
pub async fn test_receiver(number: i8) {
let mut receiver = DialogueRequest::get_dart_signal_receiver();
println!("Test receiver number is {}", number);
while let Some(_dart_signal) = receiver.recv().await {
println!("Test receiver number is {}", number + 100);
}
}
#[cfg(test)]
mod tests {
use std::{cell::RefCell, sync::Mutex};
use crate::messages::dialogue::DIALOGUE_REQUEST_SENDER;
use super::*;
use tokio_with_wasm::tokio;
#[tokio::test]
async fn test_receive_character_creation_change() {
tokio::spawn(test_receiver(1));
tokio::time::sleep(tokio::time::Duration::from_millis(10)).await;
let binding = DIALOGUE_REQUEST_SENDER
.get_or_init(|| Mutex::new(RefCell::new(None)))
.lock()
.unwrap();
let binding = binding.borrow();
let sender = binding.as_ref().unwrap();
if let Ok(_result) = sender
.send(rinf::DartSignal::<DialogueRequest> {
message: DialogueRequest {},
blob: None,
})
.await
{
println!("Sent dialogue request");
}
tokio::time::sleep(Duration::from_millis(100)).await; // <<<<<<<< ADD THIS LINE
}
} For the second problem, you need to call extern "C" {
fn prepare_isolate_extern(port: i64);
} unsafe {
prepare_isolate_extern(42);
} |
Beta Was this translation helpful? Give feedback.
Hi @TheTharin :)
For the first problem, I suggest you to sleep for some time after sending the signal so that
tokio
runtime and its event loop can keep alive for some more time, allowing the receiver to receive the signal.