Questions tagged [rust-tokio]

Tokio is an event-driven, non-blocking I/O platform for writing asynchronous applications with the Rust programming language.

Tokio aims to be:

  • Fast: Tokio's zero-cost abstractions give you bare-metal performance.

  • Productive: Tokio makes it easy to implement protocols and program asynchronously.

  • Reliable: Tokio leverages Rust's ownership and concurrency model to ensure thread safety.

  • Scalable: Tokio has a minimal footprint, and handles backpressure and cancellation naturally.

At a high level, it provides a few major components:

  • A multithreaded, work-stealing based task scheduler.
  • A reactor backed by the operating system's event queue (epoll, kqueue, IOCP, etc...).
  • Asynchronous TCP and UDP sockets.

You can find more information in

1053 questions
-1
votes
1 answer

What happens in Tokio's run_queue when you call the standard library's channel recv or try_recv methods?

I'm not sure what would happen if you used the standard library's channel implementation in the following cases. Case 1 let (tx, rx) = std::sync::mpsc::unbounded_channel(); // some code where multiple producers are sending data through…
pandawithcat
  • 571
  • 2
  • 13
-1
votes
1 answer

Is it possible to await a future inside a result without a match statement?

I have the following implementation block which isn't very readable. impl Xbee { async fn new(xbee_ip: Ipv4Addr) -> Result { match tokio::net::UdpSocket::bind((Ipv4Addr::UNSPECIFIED, 0)).await …
mallwright
  • 1,670
  • 14
  • 31
-1
votes
1 answer

Why is printing an array of bytes shown out of order?

I'm writing a method that receives an instance of bytes::Bytes representing a Type/Length/Value data structure where byte 0 is the type, the next 4 the length and the remaining the value. I implemented a unit test that is behaving a very unexpected…
ruipacheco
  • 15,025
  • 19
  • 82
  • 138
-1
votes
1 answer

Creating TcpStream within async block fails due to return error?

I'm following the documentation for tokio::runtime::Runtime and trying to adapt it to create a TcpStream that serves as a client to a remote server. I'd like to have the support of a thread pool because my applications may have hundreds of clients…
ruipacheco
  • 15,025
  • 19
  • 82
  • 138
-1
votes
1 answer

How to cancel future/close stream in multithreaded tokio?

Based on tokio's example at https://github.com/tokio-rs/tokio/blob/master/examples/proxy.rs let (mut ri, mut wi) = inbound.split(); let (mut ro, mut wo) = outbound.split(); let client_to_server = io::copy(&mut ri, &mut wo); let server_to_client =…
user2123288
  • 1,103
  • 1
  • 13
  • 22
-1
votes
1 answer

Cannot use Stream::take_while on an mpsc::channel: bool: Future is not satisfied

I want to run an event loop in one thread and handle data from a UDP socket until another thread signals to stop work. This is a difficult task for me, so I want to start from a simpler task: one thread starting the event loop and waiting for…
user1244932
  • 7,352
  • 5
  • 46
  • 103
-1
votes
1 answer

Matching future types

I am attempting to work with futures to look up asynchronously look up a value. If that value exists I want to return it and if it does not I want to create it. // A network will be created unless one already exists with this name pub fn…
BBS
  • 1,351
  • 2
  • 12
  • 27
-1
votes
1 answer

How do I extract messages from an unbounded queue every N seconds and spawn them on to a Tokio handler?

I am trying to extract messages (which are futures themselves) from an unbounded queue every N seconds and spawn them into the Tokio handler. I’ve tried dozens of variations but I cannot seem to find the right approach. It looks like it should be…
Arkaitz Jimenez
  • 22,500
  • 11
  • 75
  • 105
-1
votes
1 answer

A TCP echo server never replies even though I am sending a newline

I am trying to follow the Tokio client tutorial to write a client that talks to an echo server that sends back the response with a newline at the end. Here is what I have: extern crate futures; extern crate tokio_core; extern crate tokio_io; use…
ACC
  • 2,488
  • 6
  • 35
  • 61
-2
votes
0 answers

What is the best practice to handle associated data with a future in FuturesUnordered?

I have a dynamic number of "streams" (it's actually a Quinn crate RecvStream that doesn't implement the Copy trait) and I call this code on it: let fut = stream.read(&mut buffer); streams.push(fut); The buffer is a simple &[u8] and the streams is…
Cthutu
  • 8,713
  • 7
  • 33
  • 49
-2
votes
1 answer

Warp with Mongo DB Global Resource Injection

I have set up a database connection but I want to share it with my warp API handlers. my Cargo.toml [package] name = "mongo-warp" version = "0.1.0" edition = "2021" # See more keys and their definitions at…
Bill
  • 4,614
  • 13
  • 77
  • 132
-2
votes
2 answers

How do I accept two 2d matrix and multiply print the answer in proper format?

I have written a program to accept and print but getting errors in accepting 2d arrays. error:- thread 'main' panicked at 'called Result::unwrap() on an Err value: ParseIntError { kind: InvalidDigit }', test1.rs:15:39 note: run with RUST_BACKTRACE=1…
-2
votes
1 answer

Rust Deserializing JSON

I am having trouble deserializing json data sent from my client. server.rs use std::collections::HashMap; use std::sync::{Arc,Mutex}; use tokio::net::{TcpListener, TcpStream}; use tokio::io::{AsyncWriteExt, AsyncReadExt}; use serde_json::{…
-2
votes
1 answer

Calling async function inside of async function results in lifetime issues

The function run_av_check receives a vector filled with URLs which need to get called using reqwest. Iterating through the URLs gives me the error that the borrowed value does not live long enough. My understanding is that as long as…
Timo
  • 429
  • 3
  • 12
-2
votes
1 answer

How do I write an async method with Tokio?

I'm trying to write a library that will connect to remote servers and exchange data. I did this in C++ using Boost::Asio and am trying to do the same with Rust. One of the problems I have is mapping concepts from Asio, like async_write/read to…
ruipacheco
  • 15,025
  • 19
  • 82
  • 138
1 2 3
70
71