mirror of https://github.com/stjepang/smol
commit
4f24a6df68
|
@ -18,7 +18,7 @@ use crate::context;
|
|||
/// This function polls the future in a loop, parking the current thread after each step to wait
|
||||
/// until its waker is woken.
|
||||
///
|
||||
/// Unlike [`run`], it does not run executors or poll the reactor!
|
||||
/// Unlike [`run()`], it does not run executors or poll the reactor!
|
||||
///
|
||||
/// You can think of it as the easiest and most efficient way of turning an async operation into a
|
||||
/// blocking operation.
|
||||
|
@ -40,6 +40,8 @@ use crate::context;
|
|||
/// Timer::after(Duration::from_secs(1)).await;
|
||||
/// })
|
||||
/// ```
|
||||
///
|
||||
/// [`run()`]: crate::run()
|
||||
pub fn block_on<T>(future: impl Future<Output = T>) -> T {
|
||||
thread_local! {
|
||||
// Parker and waker associated with the current thread.
|
||||
|
|
|
@ -49,6 +49,8 @@ pub(crate) type Runnable = async_task::Task<()>;
|
|||
/// assert_eq!(task.await, 3);
|
||||
/// # });
|
||||
/// ```
|
||||
///
|
||||
/// [`run()`]: crate::run()
|
||||
#[must_use = "tasks get canceled when dropped, use `.detach()` to run them in the background"]
|
||||
#[derive(Debug)]
|
||||
pub struct Task<T>(pub(crate) Option<async_task::JoinHandle<T, ()>>);
|
||||
|
@ -68,6 +70,8 @@ impl<T: 'static> Task<T> {
|
|||
/// assert_eq!(task.await, 3);
|
||||
/// # })
|
||||
/// ```
|
||||
///
|
||||
/// [`run()`]: crate::run()
|
||||
pub fn local(future: impl Future<Output = T> + 'static) -> Task<T> {
|
||||
ThreadLocalExecutor::spawn(future)
|
||||
}
|
||||
|
@ -88,6 +92,8 @@ impl<T: Send + 'static> Task<T> {
|
|||
/// assert_eq!(task.await, 3);
|
||||
/// # });
|
||||
/// ```
|
||||
///
|
||||
/// [`run()`]: crate::run()
|
||||
pub fn spawn(future: impl Future<Output = T> + Send + 'static) -> Task<T> {
|
||||
WorkStealingExecutor::get().spawn(future)
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
//! Of course, work-stealing still causes contention in some cases, but much less often.
|
||||
//!
|
||||
//! More about work stealing: https://en.wikipedia.org/wiki/Work_stealing
|
||||
//!
|
||||
//! [`run()`]: crate::run()
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::future::Future;
|
||||
|
|
Loading…
Reference in New Issue