livekit / rust-sdks

LiveKit realtime and server SDKs for Rust
https://livekit.io
Apache License 2.0
184 stars 44 forks source link

cannot find function `spawn` in crate `livekit_runtime` #399

Closed Thintin914 closed 2 weeks ago

Thintin914 commented 3 weeks ago

Hello, first of all, thank you for the amazing work of LiveKit Rust support. I struggled to find a good rust realtime server-client sdk for weeks. I switched from AWS Gamelift to LiveKit to try something new.

I added livekit = "0.3.2" to my Cargo.toml. I think it cannot get tokio in livekit_runtime.

Is there a temporary fork to resolve this issue? The same issue also happened in https://github.com/livekit/rust-sdks/issues/380.

error[E0425]: cannot find function `spawn` in crate `livekit_runtime`
  --> /Users/wulongting/.cargo/registry/src/index.crates.io-6f17d22bba15001f/livekit-protocol-0.3.4/src/debouncer.rs:38:22
   |
38 |     livekit_runtime::spawn(debounce_task(duration, future, rx, cancel_rx));
   |                      ^^^^^ not found in `livekit_runtime`
   |
help: consider importing one of these items
   |
15 + use std::thread::spawn;
   |
15 + use tokio::spawn;
   |
help: if you import `spawn`, refer to it directly
   |
38 -     livekit_runtime::spawn(debounce_task(duration, future, rx, cancel_rx));
38 +     spawn(debounce_task(duration, future, rx, cancel_rx));
   |

error[E0425]: cannot find function `sleep` in crate `livekit_runtime`
  --> /Users/wulongting/.cargo/registry/src/index.crates.io-6f17d22bba15001f/livekit-protocol-0.3.4/src/debouncer.rs:54:34
   |
54 |             _ = livekit_runtime::sleep(duration) => {
   |                                  ^^^^^ not found in `livekit_runtime`
   |
help: consider importing one of these items
   |
15 + use std::thread::sleep;
   |
15 + use tokio::time::sleep;
   |
help: if you import `sleep`, refer to it directly
   |
54 -             _ = livekit_runtime::sleep(duration) => {
54 +             _ = sleep(duration) => {
   |

   Compiling tungstenite v0.20.1
   Compiling epaint v0.28.1
   Compiling core-video-sys v0.1.4
   Compiling tokio-tungstenite v0.20.1
For more information about this error, try `rustc --explain E0425`.
error: could not compile `livekit-protocol` (lib) due to 2 previous errors
nbsp commented 3 weeks ago

livekit_runtime should use tokio if it's specified as a dependency in your Cargo.toml and livekit has its default features set. if you're using livekit-api directly, you need to add the signal-client-tokio feature to it. could you send your Cargo.toml?

Thintin914 commented 3 weeks ago

I only list some crates that is related:

[dependencies]
tokio = { version = "1", features = ["full"]}

livekit = "0.3.2"
livekit-api = "0.3.2"

My Cargo.toml also has tokio because I need to use it elsewhere. I don't know if that might cause error.

nbsp commented 3 weeks ago

please update livekit and livekit-api to the newest versions published on crates.io just now, they should fix the issue

Thintin914 commented 2 weeks ago

Thank you for fixing the issue. I updated the crate version and it's fine now.

[dependencies]
livekit = "0.5.1"
livekit-api = "0.4.0"