mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-10-01 12:20:39 +00:00
runtime: make the enter
example deterministic (#6351)
This commit is contained in:
parent
1f924f95f1
commit
3133af42e1
@ -368,12 +368,13 @@ impl Runtime {
|
|||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use tokio::runtime::Runtime;
|
/// use tokio::runtime::Runtime;
|
||||||
|
/// use tokio::task::JoinHandle;
|
||||||
///
|
///
|
||||||
/// fn function_that_spawns(msg: String) {
|
/// fn function_that_spawns(msg: String) -> JoinHandle<()> {
|
||||||
/// // Had we not used `rt.enter` below, this would panic.
|
/// // Had we not used `rt.enter` below, this would panic.
|
||||||
/// tokio::spawn(async move {
|
/// tokio::spawn(async move {
|
||||||
/// println!("{}", msg);
|
/// println!("{}", msg);
|
||||||
/// });
|
/// })
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// fn main() {
|
/// fn main() {
|
||||||
@ -383,7 +384,10 @@ impl Runtime {
|
|||||||
///
|
///
|
||||||
/// // By entering the context, we tie `tokio::spawn` to this executor.
|
/// // By entering the context, we tie `tokio::spawn` to this executor.
|
||||||
/// let _guard = rt.enter();
|
/// let _guard = rt.enter();
|
||||||
/// function_that_spawns(s);
|
/// let handle = function_that_spawns(s);
|
||||||
|
///
|
||||||
|
/// // Wait for the task before we end the test.
|
||||||
|
/// rt.block_on(handle).unwrap();
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn enter(&self) -> EnterGuard<'_> {
|
pub fn enter(&self) -> EnterGuard<'_> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user