33 releases

0.3.30 Dec 24, 2023
0.3.29 Oct 26, 2023
0.3.28 Mar 30, 2023
0.3.25 Oct 20, 2022
0.2.0-beta Mar 20, 2018

#521 in Asynchronous

Download history 1290080/week @ 2024-01-03 1382896/week @ 2024-01-10 1528298/week @ 2024-01-17 1513376/week @ 2024-01-24 1618099/week @ 2024-01-31 1532721/week @ 2024-02-07 1589865/week @ 2024-02-14 1689516/week @ 2024-02-21 1719305/week @ 2024-02-28 1649779/week @ 2024-03-06 1581479/week @ 2024-03-13 1620872/week @ 2024-03-20 1532433/week @ 2024-03-27 1635459/week @ 2024-04-03 1632371/week @ 2024-04-10 1340578/week @ 2024-04-17

6,443,520 downloads per month
Used in 4,319 crates (187 directly)

MIT/Apache

705KB
13K SLoC

futures-executor

Executors for asynchronous tasks based on the futures-rs library.

Usage

Add this to your Cargo.toml:

[dependencies]
futures-executor = "0.3"

The current futures-executor requires Rust 1.56 or later.

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


lib.rs:

Built-in executors and related tools.

All asynchronous computation occurs within an executor, which is capable of spawning futures as tasks. This module provides several built-in executors, as well as tools for building your own.

All items are only available when the std feature of this library is activated, and it is activated by default.

Using a thread pool (M:N task scheduling)

Most of the time tasks should be executed on a thread pool. A small set of worker threads can handle a very large set of spawned tasks (which are much lighter weight than threads). Tasks spawned onto the pool with the spawn_ok function will run ambiently on the created threads.

Spawning additional tasks

Tasks can be spawned onto a spawner by calling its spawn_obj method directly. In the case of !Send futures, spawn_local_obj can be used instead.

Single-threaded execution

In addition to thread pools, it's possible to run a task (and the tasks it spawns) entirely within a single thread via the LocalPool executor. Aside from cutting down on synchronization costs, this executor also makes it possible to spawn non-Send tasks, via spawn_local_obj. The LocalPool is best suited for running I/O-bound tasks that do relatively little work between I/O operations.

There is also a convenience function block_on for simply running a future to completion on the current thread.

Dependencies