Releases: tokio-rs/tokio
Tokio v0.2.7
This release includes both bug fixes and incremental improvements across most of Tokio. The primary bug fixes are to Runtime configured with basic_scheduler and task::LocalSet.
Fixes
- potential deadlock when dropping
basic_schedulerRuntime. - calling
spawn_blockingfrom within aspawn_blocking(#2006). - storing a
Runtimeinstance in a thread-local (#2011). - miscellaneous documentation fixes.
- rt: fix
Waker::will_waketo return true when tasks match (#2045). - test-util:
time::advanceruns pending tasks before changing the time (#2059).
Added
net::lookup_hostmaps aT: ToSocketAddrsto a stream ofSocketAddrs(#1870).process::Childfields are made public to matchstd(#2014).- impl
Streamforsync::broadcast::Receiver(#2012). sync::RwLockprovides an asynchonous read-write lock (#1699).runtime::Handle::currentreturns the handle for the current runtime (#2040).StreamExt::filterfilters stream values according to a predicate (#2001).StreamExt::filter_mapsimultaneously filter and map stream values (#2001).StreamExt::try_nextconvenience for streams ofResult<T, E>(#2005).StreamExt::takelimits a stream to a specified number of values (#2025).StreamExt::take_whilelimits a stream based on a predicate (#2029).StreamExt::alltests if every element of the stream matches a predicate (#2035).StreamExt::anytests if any element of the stream matches a predicate (#2034).task::LocalSet.awaitruns spawned tasks until the set is idle (#1971).time::DelayQueue::lenreturns the number entries in the queue (#1755).- expose runtime options from the
#[tokio::main]and#[tokio::test](#2022).
Tokio v0.2.6
This release fixes an API regression introduced as part of v0.2.5.
Fixes
fs::File::seekAPI regression (#1991).
Tokio v0.2.5
Includes new APIs, utilities, and fixes. Some highlights:
tokio::sync::broadcast
A multi-producer, multi-consumer channel where each sent value is sent to all consumers (fan-out). The channel is bounded and when consumers lag, they will receive an error indicating they have lagged too far behind.
use tokio::sync::broadcast;
#[tokio::main]
async fn main() {
let (tx, mut rx1) = broadcast::channel(16);
let mut rx2 = tx.subscribe();
tokio::spawn(async move {
assert_eq!(rx1.recv().await.unwrap(), 10);
assert_eq!(rx1.recv().await.unwrap(), 20);
});
tokio::spawn(async move {
assert_eq!(rx2.recv().await.unwrap(), 10);
assert_eq!(rx2.recv().await.unwrap(), 20);
});
tx.send(10).unwrap();
tx.send(20).unwrap();
}Senders never block. When the channel is full, the oldest value still held by the channel is overwritten. This tends to be the desired behavior in order to prevent slow consumers from blocking the entire system. However, you can use a Semaphore (also added in this release) to ensure that all consumers see all messages.
tokio::sync::Semaphore
A counting synchronization primitive. It is used to limit a critical section to 1 or more concurrent tasks. For example, assume we wish to limit the number of in-flight database queries, we could do something like:
struct MyDbClient {
db: MyDbHandle,
semaphore: tokio::sync:Semaphore,
}
async fn query(client: &MyDbClient, query: Query) -> QueryResult {
let _permit = client.semaphore.acquire().await;
client.db.query(query).await
}There may be any number of concurrent calls to query, but the semaphore will limit the number that are able to concurrently perform the query.
Added
io::AsyncSeektrait (#1924).Mutex::try_lock(#1939)mpsc::Receiver::try_recvandmpsc::UnboundedReceiver::try_recv(#1939).writevsupport forTcpStream(#1956).time::throttlefor throttling streams (#1949).- implement
Streamfortime::DelayQueue(#1975). sync::broadcastprovides a fan-out channel (#1943).sync::Semaphoreprovides an async semaphore (#1973).stream::StreamExtprovides stream utilities (#1962).
Fixes
- deadlock risk while shutting down the runtime (#1972).
- panic while shutting down the runtime (#1978).
sync::MutexGuarddebug output (#1961).- misc doc improvements (#1933, #1934, #1940, #1942).
Changes
- runtime threads are configured with
runtime::Builder::core_threadsand
runtime::Builder::max_threads.runtime::Builder::num_threadsis
deprecated (#1977).
Tokio v0.2.4
A small release to fix a potential deadlock when using Mutex.
Fixes
sync::Mutexdeadlock whenlock()future is dropped early (#1898).
Tokio v0.2.3
Mostly a bug fix, doc improvement, and polish release. The biggest new addition are the new helpers to read and write integers. They are on AsyncReadExt and AsyncWriteExt and can make protocol encoding / decoding easier. For example, working with length delimited payloads might look like:
use tokio::io::{self, AsyncReadExt, AsyncWriteExt, BufStream};
use tokio::net::TcpStream;
async fn read_frame(src: &mut BufStream<TcpStream>) -> io::Result<Vec<u8>> {
let len = src.read_u32().await?;
let mut frame = vec![0; len as usize];
src.read_exact(&mut frame).await?;
Ok(frame)
}
async fn write_frame(dst: &mut BufStream<TcpStream>, frame: &[u8]) -> io::Result<()> {
dst.write_u32(frame.len() as u32).await?;
dst.write_all(frame).await?;
dst.flush().await?;
Ok(())
}Added
- read / write integers using
AsyncReadExtandAsyncWriteExt(#1863). read_buf/write_buffor reading / writingBuf/BufMut(#1881).TcpStream::poll_peek- pollable API for performing TCP peek (#1864).sync::oneshot::error::TryRecvErrorprovides variants to detect the error
kind (#1874).LocalSet::block_onaccepts!'statictask (#1882).task::JoinErroris nowSync(#1888).- impl conversions between
tokio::time::Instantand
std::time::Instant(#1904).
Fixes
Tokio v0.2.2
Primarily a release fix for basic_scheduler and task::LocalSet.
task::LocalSet was introduced in v0.2.1 and provides tooling to run !Send tasks. The task::LocalSet structure replaces the need to have separate runtimes. The advantage being that it can be used with the threaded runtime in order to run both Send futures across multiple threads and !Send futures on the current thread.
use tokio::runtime::Runtime;
use tokio::task;
use std::rc::Rc;
let unsend_data = Rc::new("my unsend data...");
let mut rt = Runtime::new().unwrap();
// Construct a local task set that can run `!Send` futures.
let local = task::LocalSet::new();
// Run the local task group.
local.block_on(&mut rt, async move {
let unsend_data = unsend_data.clone();
// `spawn_local` ensures that the future is spawned on the local
// task group.
task::spawn_local(async move {
println!("{}", unsend_data);
// ...
}).await.unwrap();
});Fixes
- scheduling with
basic_scheduler(#1861). - update
spawnpanic message to specify that a task scheduler is required (#1839). - API docs example for
runtime::Builderto include a task scheduler (#1841). - general documentation (#1834).
- building on illumos/solaris (#1772).
- panic when dropping
LocalSet(#1843). - API docs mention the required Cargo features for
Builder::basic_schedulerandBuilder::threaded_scheduler(#1858).
Added
- impl
Streamforsignal::unix::Signal(#1849). - API docs for platform specific behavior of
signal::ctrl_candsignal::unix::Signal(#1854). - API docs for
signal::unix::Signal::{recv, poll_recv}andsignal::windows::CtrlBreak::{recv, poll_recv}(#1854). File::into_stdandFile::try_into_stdmethods (#1856).
Tokio v0.2.1
Tokio v0.2.0
A major breaking change. Most implementation and APIs have changed one way or
another. This changelog entry contains a highlight
Changed
- APIs are updated to use
async / await. - most
tokio-*crates are collapsed into this crate. - Scheduler is rewritten.
tokio::spawnreturns aJoinHandle.- A single I/O / timer is used per runtime.
- I/O driver uses a concurrent slab for allocating state.
- components are made available via feature flag.
- Use
bytes0.5 tokio::codecis moved totokio-util.
Removed
- Standalone
timerandnetdrivers are removed, useRuntimeinstead current_threadruntime is removed, usetokio::runtime::Runtimewith
basic_schedulerinstead.
v0.2.0-alpha.5
Changed
- sync: rename
Lock->Mutexand make it more likestd::sync::Mutex(#1573). - time: rename
sleeptodelay_for(#1518).
Fixed
- executor: shutdown blocking pool threads when idle (#1562, #1514).
- fs: propagate flush for stdout / stderr. (#1528).
- net: API documentation generation (#1575).
Added
- io: bring back generic
splitforAsyncRead + AsyncWrite(#1521). - io: enable buffering both reads and writes on the same type (#1558).
- process: platform specific
Commandmethods (#1516). - process: implement
From<std::process::Command>forCommand(#1513). - tls:
TlsStream::get_refandTlsStream::get_mut(#1537).