Questions tagged [rust-futures]

69 questions
1
vote
0 answers

tokio::join on mapped futures that return trait types has the error "implementation of `FnOnce` is not general enough"

I have started multiple tasks with tokio::spawn and I want to collect the reasons why they exited as dyn std::error::Error. If any of the tasks panic, I want to forward the panic instantly without waiting for the other tasks. To achieve this, I used…
miszcz2137
  • 894
  • 6
  • 18
1
vote
1 answer

Why does futures::lock::Mutex not implement RefUnwindSafe

futures::lock::Mutex is not implementing RefUnwindSafe trait (see https://docs.rs/futures/0.3.17/futures/lock/struct.Mutex.html#impl-RefUnwindSafe ) Why is not safe to pass a futures::lock::Mutex inside std::panic::catch_unwind? Reproducible…
allevo
  • 844
  • 1
  • 9
  • 20
1
vote
1 answer

push on SelectAll Stream

I would like to have a struct for handling some streams. All streams share the same Item. The logic is the following: I need to create a unique stream that contains all items that came from all other streams. I need also to add "new" stream to the…
allevo
  • 844
  • 1
  • 9
  • 20
1
vote
1 answer

How to concurrently crawl paginated webpages with unknown end?

I'm trying to write a web crawler in Rust using the tokio asynchronous runtime. I want to fetch/process multiple pages asynchronously but I also want the crawler to stop when it reaches the end (in other words if there is nothing left to crawl). So…
orhun
  • 89
  • 2
  • 5
1
vote
1 answer

Why does implementing ArcWake avoid writing boilerplate?

When building async futures, it's common to implement the ArcWake trait in wakers. I understand this is done to avoid writing boilerplate, creating vtables and writing unsafe code (according to the tokio tutorial). Now, (and this feels like a silly…
jgpaiva
  • 369
  • 2
  • 11
0
votes
2 answers

How to call an async function with a non-static reference in `poll` in rust?

I've encountered an obstacle when trying to implement Future. I need to poll another async function in my poll function which only takes in &str. It looks something like this: async fn make_query(query: &str) -> i32 { // Magic happens …
Einliterflasche
  • 473
  • 6
  • 18
0
votes
1 answer

Rust Tokio select macro conditional sleep branch

I have an async select macro loop that handles user inputs and event intervals within a CLI game that I am writing. I would like to be able to conditionally set a sleep countdown within it as well. I have tried declaring an Option that's…
Chambers
  • 21
  • 3
0
votes
1 answer

Futures-Util version issue

My code was working fine until today I got the error error: the 'rustc.exe' binary, normally provided by the 'rustc' component, is not applicable to the 'stable-x86_64-pc-windows-msvc' toolchain I fixed it with rustup toolchain install stable After…
Zubayr
  • 457
  • 4
  • 18
0
votes
0 answers

What is the established way to call the waker of a future when it does IO?

I have a future that reads from a socket via OS API. My current implementation spawns an internal thread, which polls the socket and calls the waker when there is some ready data. This internal thread seems to me an unnecessary overhead. How to call…
nicolai
  • 1,140
  • 9
  • 17
0
votes
1 answer

How to run a tonic server in the background for a test

Problem I'm learning about Tonic. I'm trying to write an automated test where I spin up a server in the background, call it via a generated client, and then stop the server. Attempts What I have currently looks like this: //... pub fn build(inv:…
bart-kosmala
  • 931
  • 1
  • 11
  • 20
0
votes
1 answer

Why does a pinned future implement Unpin?

fn test(t: T) { } fn main() { let a = 1; let b = async { 1 }; test(b) // the trait `Unpin` is not implemented for `[async block]` } Future is not Unpin, so why does pinning it (pin_mut, Box::pin, etc., which wrap…
BugMaker
  • 111
  • 1
  • 3
0
votes
0 answers

Is there a dynamic alternative to tokio's `select!` macro?

I have an application that listens for messages from multiple channels at the same it. If there were a hard-coded amount of channels, this would be trivial. From the tokio docs: use tokio::sync::mpsc; #[tokio::main] async fn main() { let (tx1,…
Jake
  • 2,090
  • 2
  • 11
  • 24
0
votes
1 answer

Borrowed data escapes outside of joined task

I have two fallible async functions I want to execute in parallel. The problem is that both functions take a reference, and the parameters to my wrapper function are also references. This gives me an error when I try to use task::spawn because the…
Brandon Piña
  • 614
  • 1
  • 6
  • 20
0
votes
1 answer

Updating UI elements from a async loop

What is the standard method for updating UI elements from a loop calling a web request in Rust using gtk-rs? I am having trouble updating a label in a UI element to display some data from a web request. Is there a standard way of doing this? The…
John554
  • 145
  • 1
  • 7
0
votes
0 answers

enabling a feature when using libraries

I'm trying to use DefaultAsyncInterface of tunio which depends on tokio feature (here) I have added tunio with async-tokio feature in Cargo.toml: [dependencies] env_logger = "0.10.0" etherparse = "0.13.0" futures = "0.3.25" netconfig = "0.4.0" tokio…
AQA
  • 21
  • 2