Skip to content

Commit 32bf6c1

Browse files
committed
fix multithreaded+simulator combination
We only added the simulator feature for the unti tests, which run in a single thread. This adds support for using the simulator function with the multithreaded feature.
1 parent d6490ca commit 32bf6c1

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ required-features = ["usb", "tokio/rt", "tokio/macros", "rlp"]
9191
name = "cardano"
9292
required-features = ["usb", "tokio/rt", "tokio/macros"]
9393

94+
[[example]]
95+
name = "simulator"
96+
required-features = ["simulator", "tokio/rt", "tokio/macros", "tokio/rt-multi-thread", "multithreaded"]
97+
9498
[profile.release]
9599
# Reduce wasm binary size.
96100
opt-level = 'z'

Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ example-eth:
1818
cargo run --example eth --features=usb,tokio/rt,tokio/macros,rlp
1919
example-cardano:
2020
cargo run --example cardano --features=usb,tokio/rt,tokio/macros
21+
example-simulator:
22+
cargo run --example simulator --features=simulator,tokio/rt,tokio/macros,tokio/rt-multi-thread,multithreaded
2123
wasm:
2224
wasm-pack build --release --features=wasm
2325
cp webhid.js pkg/

examples/simulator.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
async fn demo<R: bitbox_api::runtime::Runtime + Sync + Send>() {
2+
let noise_config = Box::new(bitbox_api::NoiseConfigNoCache {});
3+
let bitbox = bitbox_api::BitBox::<R>::from_simulator(None, noise_config)
4+
.await
5+
.unwrap();
6+
let pairing_bitbox = bitbox.unlock_and_pair().await.unwrap();
7+
let paired_bitbox = pairing_bitbox.wait_confirm().await.unwrap();
8+
println!(
9+
"device info: {:?}",
10+
paired_bitbox.device_info().await.unwrap()
11+
);
12+
}
13+
14+
#[tokio::main]
15+
async fn main() {
16+
demo::<bitbox_api::runtime::TokioRuntime>().await
17+
}

src/simulator.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ pub async fn try_connect<R: Runtime>(endpoint: Option<&str>) -> Result<Box<TcpCl
4242

4343
impl crate::util::Threading for TcpClient {}
4444

45-
#[async_trait(?Send)]
45+
#[cfg_attr(feature = "multithreaded", async_trait)]
46+
#[cfg_attr(not(feature="multithreaded"), async_trait(?Send))]
4647
impl ReadWrite for TcpClient {
4748
fn write(&self, msg: &[u8]) -> Result<usize, CommunicationError> {
4849
let mut stream = self.stream.lock().unwrap();

0 commit comments

Comments
 (0)