id stringlengths 22 133 | text stringlengths 40 40.2k | arch stringclasses 1
value | syntax stringclasses 1
value | kind stringclasses 4
values | repo stringclasses 27
values | path stringlengths 5 116 | license stringclasses 6
values | commit stringlengths 40 40 | source_host stringclasses 1
value | category stringclasses 16
values | source_url stringlengths 85 196 | line_start int64 1 4.28k | line_end int64 4 4.31k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
tokio-rs/tokio:tokio/src/task/builder.rs:5 | self,
future: Fut,
local_set: &LocalSet,
) -> io::Result<JoinHandle<Fut::Output>>
where
Fut: Future + 'static,
Fut::Output: 'static,
{
let fut_size = mem::size_of::<Fut>();
Ok(if fut_size > BOX_FUTURE_THRESHOLD {
local_set.spawn_named(Box::pin(futu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/task/builder.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/task/builder.rs:6 | ///
/// [runtime handle]: crate::runtime::Handle
/// [`Handle::spawn_blocking`]: crate::runtime::Handle::spawn_blocking
#[track_caller]
pub fn spawn_blocking_on<Function, Output>(
self,
function: Function,
handle: &Handle,
) -> io::Result<JoinHandle<Output>>
where
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/task/builder.rs | 201 | 235 |
tokio-rs/tokio:tokio/src/task/builder.rs:3 | ///
/// This method panics if called outside of a Tokio runtime.
///
/// See [`task::spawn`](crate::task::spawn()) for
/// more details.
#[track_caller]
pub fn spawn<Fut>(self, future: Fut) -> io::Result<JoinHandle<Fut::Output>>
where
Fut: Future + Send + 'static,
Fut::Output... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | d25778f67d4571f9067a0004133d5a9005b6aedd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d25778f67d4571f9067a0004133d5a9005b6aedd/tokio/src/task/builder.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/task/builder.rs:4 | /// Spawns `!Send` a task on the current [`LocalSet`] or [`LocalRuntime`] with
/// this builder's settings.
///
/// The spawned future will be run on the same thread that called `spawn_local`.
/// This may only be called from the context of a [local task set][`LocalSet`]
/// or a [`LocalRuntime`].
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | d25778f67d4571f9067a0004133d5a9005b6aedd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d25778f67d4571f9067a0004133d5a9005b6aedd/tokio/src/task/builder.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/task/builder.rs:3 | ///
/// This method panics if called outside of a Tokio runtime.
///
/// See [`task::spawn`](crate::task::spawn()) for
/// more details.
#[track_caller]
pub fn spawn<Fut>(self, future: Fut) -> io::Result<JoinHandle<Fut::Output>>
where
Fut: Future + Send + 'static,
Fut::Output... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | c3a935541d911cd9afa6838a1bb02e4f499b244d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c3a935541d911cd9afa6838a1bb02e4f499b244d/tokio/src/task/builder.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/task/builder.rs:4 | /// Spawns `!Send` a task on the current [`LocalSet`] with this builder's
/// settings.
///
/// The spawned future will be run on the same thread that called `spawn_local`.
/// This may only be called from the context of a [local task set][`LocalSet`].
///
/// # Panics
///
/// This funct... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | c3a935541d911cd9afa6838a1bb02e4f499b244d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c3a935541d911cd9afa6838a1bb02e4f499b244d/tokio/src/task/builder.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/task/builder.rs:5 | ) -> io::Result<JoinHandle<Fut::Output>>
where
Fut: Future + 'static,
Fut::Output: 'static,
{
let fut_size = mem::size_of::<Fut>();
Ok(if fut_size > BOX_FUTURE_THRESHOLD {
local_set.spawn_named(Box::pin(future), SpawnMeta::new(self.name, fut_size))
} else {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | c3a935541d911cd9afa6838a1bb02e4f499b244d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c3a935541d911cd9afa6838a1bb02e4f499b244d/tokio/src/task/builder.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/task/builder.rs:6 | #[track_caller]
pub fn spawn_blocking_on<Function, Output>(
self,
function: Function,
handle: &Handle,
) -> io::Result<JoinHandle<Output>>
where
Function: FnOnce() -> Output + Send + 'static,
Output: Send + 'static,
{
use crate::runtime::Mandatory;
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | c3a935541d911cd9afa6838a1bb02e4f499b244d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c3a935541d911cd9afa6838a1bb02e4f499b244d/tokio/src/task/builder.rs | 201 | 232 |
tokio-rs/tokio:tokio/src/task/builder.rs:2 | /// let listener = TcpListener::bind("127.0.0.1:8080").await?;
///
/// loop {
/// let (socket, _) = listener.accept().await?;
///
/// tokio::task::Builder::new()
/// .name("tcp connection handler")
/// .spawn(async move {
/// // Process each socket concurr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | b5de84d19b4316caccfe13aa7552d895bdd7f046 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b5de84d19b4316caccfe13aa7552d895bdd7f046/tokio/src/task/builder.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/task/builder.rs:3 | /// This method panics if called outside of a Tokio runtime.
///
/// See [`task::spawn`](crate::task::spawn()) for
/// more details.
#[track_caller]
pub fn spawn<Fut>(self, future: Fut) -> io::Result<JoinHandle<Fut::Output>>
where
Fut: Future + Send + 'static,
Fut::Output: Send +... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | b5de84d19b4316caccfe13aa7552d895bdd7f046 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b5de84d19b4316caccfe13aa7552d895bdd7f046/tokio/src/task/builder.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/task/builder.rs:4 | /// The spawned future will be run on the same thread that called `spawn_local`.
/// This may only be called from the context of a [local task set][`LocalSet`].
///
/// # Panics
///
/// This function panics if called outside of a [local task set][`LocalSet`].
///
/// See [`task::spawn_local`... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | b5de84d19b4316caccfe13aa7552d895bdd7f046 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b5de84d19b4316caccfe13aa7552d895bdd7f046/tokio/src/task/builder.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/task/builder.rs:5 | {
Ok(local_set.spawn_named(future, self.name))
}
/// Spawns blocking code on the blocking threadpool.
///
/// # Panics
///
/// This method panics if called outside of a Tokio runtime.
///
/// See [`task::spawn_blocking`](crate::task::spawn_blocking)
/// for more details.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | b5de84d19b4316caccfe13aa7552d895bdd7f046 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b5de84d19b4316caccfe13aa7552d895bdd7f046/tokio/src/task/builder.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/task/builder.rs:6 | {
use crate::runtime::Mandatory;
let (join_handle, spawn_result) = if std::mem::size_of::<Function>() > BOX_FUTURE_THRESHOLD
{
handle.inner.blocking_spawner().spawn_blocking_inner(
Box::new(function),
Mandatory::NonMandatory,
self.name,... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | b5de84d19b4316caccfe13aa7552d895bdd7f046 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b5de84d19b4316caccfe13aa7552d895bdd7f046/tokio/src/task/builder.rs | 201 | 223 |
tokio-rs/tokio:tokio/src/task/builder.rs:2 | /// let listener = TcpListener::bind("127.0.0.1:8080").await?;
///
/// loop {
/// let (socket, _) = listener.accept().await?;
///
/// tokio::task::Builder::new()
/// .name("tcp connection handler")
/// .spawn(async move {
/// // Process each socket concurr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | da17c6146413d9ea14f76989efe31ef7de829f4c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/da17c6146413d9ea14f76989efe31ef7de829f4c/tokio/src/task/builder.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/task/builder.rs:3 | /// This method panics if called outside of a Tokio runtime.
///
/// See [`task::spawn`](crate::task::spawn()) for
/// more details.
#[track_caller]
pub fn spawn<Fut>(self, future: Fut) -> io::Result<JoinHandle<Fut::Output>>
where
Fut: Future + Send + 'static,
Fut::Output: Send +... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | da17c6146413d9ea14f76989efe31ef7de829f4c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/da17c6146413d9ea14f76989efe31ef7de829f4c/tokio/src/task/builder.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/task/builder.rs:4 | /// Spawns `!Send` a task on the current [`LocalSet`] with this builder's
/// settings.
///
/// The spawned future will be run on the same thread that called `spawn_local`.
/// This may only be called from the context of a [local task set][`LocalSet`].
///
/// # Panics
///
/// This funct... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | da17c6146413d9ea14f76989efe31ef7de829f4c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/da17c6146413d9ea14f76989efe31ef7de829f4c/tokio/src/task/builder.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/task/builder.rs:5 | future: Fut,
local_set: &LocalSet,
) -> io::Result<JoinHandle<Fut::Output>>
where
Fut: Future + 'static,
Fut::Output: 'static,
{
Ok(local_set.spawn_named(future, self.name))
}
/// Spawns blocking code on the blocking threadpool.
///
/// # Panics
///
/... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | da17c6146413d9ea14f76989efe31ef7de829f4c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/da17c6146413d9ea14f76989efe31ef7de829f4c/tokio/src/task/builder.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/task/builder.rs:6 | function: Function,
handle: &Handle,
) -> io::Result<JoinHandle<Output>>
where
Function: FnOnce() -> Output + Send + 'static,
Output: Send + 'static,
{
use crate::runtime::Mandatory;
let (join_handle, spawn_result) =
if cfg!(debug_assertions) && std::mem::... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | da17c6146413d9ea14f76989efe31ef7de829f4c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/da17c6146413d9ea14f76989efe31ef7de829f4c/tokio/src/task/builder.rs | 201 | 229 |
tokio-rs/tokio:tokio/src/task/builder.rs:2 | /// let listener = TcpListener::bind("127.0.0.1:8080").await?;
///
/// loop {
/// let (socket, _) = listener.accept().await?;
///
/// tokio::task::Builder::new()
/// .name("tcp connection handler")
/// .spawn(async move {
/// // Process each socket concurr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | ddd7250e620c611f5a67fc94aba906e5b3b5fb25 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ddd7250e620c611f5a67fc94aba906e5b3b5fb25/tokio/src/task/builder.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/task/builder.rs:3 | /// This method panics if called outside of a Tokio runtime.
///
/// See [`task::spawn`](crate::task::spawn()) for
/// more details.
#[track_caller]
pub fn spawn<Fut>(self, future: Fut) -> io::Result<JoinHandle<Fut::Output>>
where
Fut: Future + Send + 'static,
Fut::Output: Send +... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | ddd7250e620c611f5a67fc94aba906e5b3b5fb25 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ddd7250e620c611f5a67fc94aba906e5b3b5fb25/tokio/src/task/builder.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/task/builder.rs:4 | ///
/// [`task::spawn_local`]: crate::task::spawn_local
/// [`LocalSet`]: crate::task::LocalSet
#[track_caller]
pub fn spawn_local<Fut>(self, future: Fut) -> io::Result<JoinHandle<Fut::Output>>
where
Fut: Future + 'static,
Fut::Output: 'static,
{
Ok(super::local::spawn_lo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | ddd7250e620c611f5a67fc94aba906e5b3b5fb25 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ddd7250e620c611f5a67fc94aba906e5b3b5fb25/tokio/src/task/builder.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/task/builder.rs:5 | #[track_caller]
pub fn spawn_blocking<Function, Output>(
self,
function: Function,
) -> io::Result<JoinHandle<Output>>
where
Function: FnOnce() -> Output + Send + 'static,
Output: Send + 'static,
{
let handle = Handle::current();
self.spawn_blocking_on(fun... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | ddd7250e620c611f5a67fc94aba906e5b3b5fb25 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ddd7250e620c611f5a67fc94aba906e5b3b5fb25/tokio/src/task/builder.rs | 161 | 201 |
tokio-rs/tokio:tokio/src/task/builder.rs:2 | /// let listener = TcpListener::bind("127.0.0.1:8080").await?;
///
/// loop {
/// let (socket, _) = listener.accept().await?;
///
/// tokio::task::Builder::new()
/// .name("tcp connection handler")
/// .spawn(async move {
/// // Process each socket concurr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | 2f244514346a37bf598d8fc1c593d68771eb6047 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2f244514346a37bf598d8fc1c593d68771eb6047/tokio/src/task/builder.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/task/builder.rs:3 | /// This method panics if called outside of a Tokio runtime.
///
/// See [`task::spawn`](crate::task::spawn) for
/// more details.
#[track_caller]
pub fn spawn<Fut>(self, future: Fut) -> io::Result<JoinHandle<Fut::Output>>
where
Fut: Future + Send + 'static,
Fut::Output: Send + '... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | 2f244514346a37bf598d8fc1c593d68771eb6047 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2f244514346a37bf598d8fc1c593d68771eb6047/tokio/src/task/builder.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/task/builder.rs:4 | ///
/// [`task::spawn_local`]: crate::task::spawn_local
/// [`LocalSet`]: crate::task::LocalSet
#[track_caller]
pub fn spawn_local<Fut>(self, future: Fut) -> io::Result<JoinHandle<Fut::Output>>
where
Fut: Future + 'static,
Fut::Output: 'static,
{
Ok(super::local::spawn_lo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | ebeb78ed40027032feb77c89a1de4b58d2dcafbf | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ebeb78ed40027032feb77c89a1de4b58d2dcafbf/tokio/src/task/builder.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/task/builder.rs:5 | #[track_caller]
pub fn spawn_blocking<Function, Output>(
self,
function: Function,
) -> io::Result<JoinHandle<Output>>
where
Function: FnOnce() -> Output + Send + 'static,
Output: Send + 'static,
{
self.spawn_blocking_on(function, &context::current())
}
/... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | ebeb78ed40027032feb77c89a1de4b58d2dcafbf | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ebeb78ed40027032feb77c89a1de4b58d2dcafbf/tokio/src/task/builder.rs | 161 | 200 |
tokio-rs/tokio:tokio/src/task/builder.rs:5 | #[track_caller]
pub fn spawn_blocking<Function, Output>(
self,
function: Function,
) -> io::Result<JoinHandle<Output>>
where
Function: FnOnce() -> Output + Send + 'static,
Output: Send + 'static,
{
self.spawn_blocking_on(function, &context::current())
}
/... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | d7b3b33c9c95935c4eba70293d75a870a5d5ba24 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d7b3b33c9c95935c4eba70293d75a870a5d5ba24/tokio/src/task/builder.rs | 161 | 200 |
tokio-rs/tokio:tokio/src/task/builder.rs:5 | #[track_caller]
pub fn spawn_blocking<Function, Output>(
self,
function: Function,
) -> io::Result<JoinHandle<Output>>
where
Function: FnOnce() -> Output + Send + 'static,
Output: Send + 'static,
{
self.spawn_blocking_on(function, &context::current())
}
/... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | 5a2bc850af7bedb51b70da1486ec8057f8ea5274 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5a2bc850af7bedb51b70da1486ec8057f8ea5274/tokio/src/task/builder.rs | 161 | 200 |
tokio-rs/tokio:tokio/src/task/builder.rs:3 | /// This method panics if called outside of a Tokio runtime.
///
/// See [`task::spawn`](crate::task::spawn) for
/// more details.
#[track_caller]
pub fn spawn<Fut>(self, future: Fut) -> io::Result<JoinHandle<Fut::Output>>
where
Fut: Future + Send + 'static,
Fut::Output: Send + '... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | 3b6c74a40ad87837ab53c105a323c2807a4e1b38 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3b6c74a40ad87837ab53c105a323c2807a4e1b38/tokio/src/task/builder.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/task/builder.rs:4 | ///
/// This function panics if called outside of a [local task set][`LocalSet`].
///
/// See [`task::spawn_local`] for more details.
///
/// [`task::spawn_local`]: crate::task::spawn_local
/// [`LocalSet`]: crate::task::LocalSet
#[track_caller]
pub fn spawn_local<Fut>(self, future: Fut)... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | 3b6c74a40ad87837ab53c105a323c2807a4e1b38 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3b6c74a40ad87837ab53c105a323c2807a4e1b38/tokio/src/task/builder.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/task/builder.rs:5 | /// This method panics if called outside of a Tokio runtime.
///
/// See [`task::spawn_blocking`](crate::task::spawn_blocking)
/// for more details.
#[track_caller]
pub fn spawn_blocking<Function, Output>(
self,
function: Function,
) -> io::Result<JoinHandle<Output>>
where
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | 3b6c74a40ad87837ab53c105a323c2807a4e1b38 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3b6c74a40ad87837ab53c105a323c2807a4e1b38/tokio/src/task/builder.rs | 161 | 204 |
tokio-rs/tokio:tokio/src/task/builder.rs:2 | /// let listener = TcpListener::bind("127.0.0.1:8080").await?;
///
/// loop {
/// let (socket, _) = listener.accept().await?;
///
/// tokio::task::Builder::new()
/// .name("tcp connection handler")
/// .spawn(async move {
/// // Process each socket concurr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | 2bad98f879811760922818807157b173e58625d1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2bad98f879811760922818807157b173e58625d1/tokio/src/task/builder.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/task/builder.rs:3 | /// This method panics if called outside of a Tokio runtime.
///
/// See [`task::spawn`](crate::task::spawn) for
/// more details.
#[track_caller]
pub fn spawn<Fut>(self, future: Fut) -> JoinHandle<Fut::Output>
where
Fut: Future + Send + 'static,
Fut::Output: Send + 'static,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | 2bad98f879811760922818807157b173e58625d1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2bad98f879811760922818807157b173e58625d1/tokio/src/task/builder.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/task/builder.rs:4 | ///
/// [`task::spawn_local`]: crate::task::spawn_local
/// [`LocalSet`]: crate::task::LocalSet
#[track_caller]
pub fn spawn_local<Fut>(self, future: Fut) -> JoinHandle<Fut::Output>
where
Fut: Future + 'static,
Fut::Output: 'static,
{
super::local::spawn_local_inner(futur... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | 2bad98f879811760922818807157b173e58625d1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2bad98f879811760922818807157b173e58625d1/tokio/src/task/builder.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/task/builder.rs:5 | Output: Send + 'static,
{
self.spawn_blocking_on(function, &context::current())
}
/// Spawns blocking code on the provided [runtime handle]'s blocking threadpool.
///
/// See [`Handle::spawn_blocking`] for more details.
///
/// [runtime handle]: crate::runtime::Handle
/// [`Hand... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | 2bad98f879811760922818807157b173e58625d1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2bad98f879811760922818807157b173e58625d1/tokio/src/task/builder.rs | 161 | 191 |
tokio-rs/tokio:tokio/src/task/builder.rs:3 | /// This method panics if called outside of a Tokio runtime.
///
/// See [`task::spawn`](crate::task::spawn) for
/// more details.
#[track_caller]
pub fn spawn<Fut>(self, future: Fut) -> JoinHandle<Fut::Output>
where
Fut: Future + Send + 'static,
Fut::Output: Send + 'static,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | b1557ea5b2b0ea8d55b221e25fccb523bc1258ef | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1557ea5b2b0ea8d55b221e25fccb523bc1258ef/tokio/src/task/builder.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/task/builder.rs:2 | /// let (socket, _) = listener.accept().await?;
///
/// tokio::task::Builder::new()
/// .name("tcp connection handler")
/// .spawn(async move {
/// // Process each socket concurrently.
/// process(socket).await
/// });
/// }
/// }
/... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | 911a0efa87e36f0dffb13e3d52340d5c08415db1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/911a0efa87e36f0dffb13e3d52340d5c08415db1/tokio/src/task/builder.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/task/builder.rs:3 | Fut: Future + Send + 'static,
Fut::Output: Send + 'static,
{
super::spawn::spawn_inner(future, self.name)
}
/// Spawns a task on the current thread.
///
/// See [`task::spawn_local`](crate::task::spawn_local)
/// for more details.
#[track_caller]
pub fn spawn_local<Fut>(... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | 911a0efa87e36f0dffb13e3d52340d5c08415db1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/911a0efa87e36f0dffb13e3d52340d5c08415db1/tokio/src/task/builder.rs | 81 | 120 |
tokio-rs/tokio:tokio/src/task/builder.rs:3 | Fut: Future + Send + 'static,
Fut::Output: Send + 'static,
{
super::spawn::spawn_inner(future, self.name)
}
/// Spawns a task on the current thread.
///
/// See [`task::spawn_local`](crate::task::spawn_local)
/// for more details.
#[track_caller]
pub fn spawn_local<Fut>(... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | 8758965206d3c23c07ded0518d6c7398043ef227 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8758965206d3c23c07ded0518d6c7398043ef227/tokio/src/task/builder.rs | 81 | 115 |
tokio-rs/tokio:tokio/src/task/builder.rs:2 | /// let (socket, _) = listener.accept().await?;
///
/// tokio::task::Builder::new()
/// .name("tcp connection handler")
/// .spawn(async move {
/// // Process each socket concurrently.
/// process(socket).await
/// });
/// }
/// }
/... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | 7aad428994120b2b37cdbefd7b1dd351555c92a3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7aad428994120b2b37cdbefd7b1dd351555c92a3/tokio/src/task/builder.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/task/builder.rs:3 | Fut: Future + Send + 'static,
Fut::Output: Send + 'static,
{
super::spawn::spawn_inner(future, self.name)
}
/// Spawns a task on the current thread.
///
/// See [`task::spawn_local`](crate::task::spawn_local)
/// for more details.
#[track_caller]
pub fn spawn_local<Fut>(... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | 78e0f0b42a4f7a50f3986f576703e5a3cb473b79 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/78e0f0b42a4f7a50f3986f576703e5a3cb473b79/tokio/src/task/builder.rs | 81 | 112 |
tokio-rs/tokio:tokio/src/task/builder.rs:2 | /// .spawn(async move {
/// // Process each socket concurrently.
/// process(socket).await
/// });
/// }
/// }
/// ```
#[derive(Default, Debug)]
pub struct Builder<'a> {
name: Option<&'a str>,
}
impl<'a> Builder<'a> {
/// Creates a new task builder.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | cf3206842c0d94ecdaaeb421a58b1c963b627c3d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cf3206842c0d94ecdaaeb421a58b1c963b627c3d/tokio/src/task/builder.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/task/builder.rs:3 | #[track_caller]
pub fn spawn_local<Fut>(self, future: Fut) -> JoinHandle<Fut::Output>
where
Fut: Future + 'static,
Fut::Output: 'static,
{
super::local::spawn_local_inner(future, self.name)
}
/// Spawns blocking code on the blocking threadpool.
///
/// See [`task::sp... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | cf3206842c0d94ecdaaeb421a58b1c963b627c3d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cf3206842c0d94ecdaaeb421a58b1c963b627c3d/tokio/src/task/builder.rs | 81 | 102 |
tokio-rs/tokio:tokio/src/task/builder.rs:2 | /// .spawn(async move {
/// // Process each socket concurrently.
/// process(socket).await
/// });
/// }
/// }
/// ```
#[derive(Default, Debug)]
pub struct Builder<'a> {
name: Option<&'a str>,
}
impl<'a> Builder<'a> {
/// Creates a new task builder.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | 1f8105588c06c41c90c3c77628d10cde4b3b2edb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1f8105588c06c41c90c3c77628d10cde4b3b2edb/tokio/src/task/builder.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/task/builder.rs:3 | #[cfg_attr(tokio_track_caller, track_caller)]
pub fn spawn_local<Fut>(self, future: Fut) -> JoinHandle<Fut::Output>
where
Fut: Future + 'static,
Fut::Output: 'static,
{
super::local::spawn_local_inner(future, self.name)
}
/// Spawns blocking code on the blocking threadpool.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | 1f8105588c06c41c90c3c77628d10cde4b3b2edb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1f8105588c06c41c90c3c77628d10cde4b3b2edb/tokio/src/task/builder.rs | 81 | 102 |
tokio-rs/tokio:tokio/src/task/builder.rs:2 | /// .name("tcp connection handler")
/// .spawn(async move {
/// // Process each socket concurrently.
/// process(socket).await
/// });
/// }
/// }
/// ```
#[derive(Default, Debug)]
pub struct Builder<'a> {
name: Option<&'a str>,
}
impl<'a> Bui... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | 8fa29cb00a486c0ffc28f295c749573cb58a8967 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8fa29cb00a486c0ffc28f295c749573cb58a8967/tokio/src/task/builder.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/task/builder.rs:3 | /// for more details.
#[cfg_attr(tokio_track_caller, track_caller)]
pub fn spawn_local<Fut>(self, future: Fut) -> JoinHandle<Fut::Output>
where
Fut: Future + 'static,
Fut::Output: 'static,
{
super::local::spawn_local_inner(future, self.name)
}
/// Spawns blocking code on... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/builder.rs | MIT | 8fa29cb00a486c0ffc28f295c749573cb58a8967 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8fa29cb00a486c0ffc28f295c749573cb58a8967/tokio/src/task/builder.rs | 81 | 105 |
tokio-rs/tokio:tokio/src/task/consume_budget.rs:1 | use std::task::{ready, Poll};
/// Consumes a unit of budget and returns the execution back to the Tokio
/// runtime *if* the task's coop budget was exhausted.
///
/// The task will only yield if its entire coop budget has been exhausted.
/// This function can be used in order to insert optional yield points into long
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/consume_budget.rs | MIT | 12b2567b959ec754e6f58fb76b88a1a38f805771 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/12b2567b959ec754e6f58fb76b88a1a38f805771/tokio/src/task/consume_budget.rs | 1 | 41 |
tokio-rs/tokio:tokio/src/task/consume_budget.rs:1 | use std::task::{ready, Poll};
/// Consumes a unit of budget and returns the execution back to the Tokio
/// runtime *if* the task's coop budget was exhausted.
///
/// The task will only yield if its entire coop budget has been exhausted.
/// This function can be used in order to insert optional yield points into long
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/consume_budget.rs | MIT | 11f66f43a09169b893212b854c6c49985ff2224f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/11f66f43a09169b893212b854c6c49985ff2224f/tokio/src/task/consume_budget.rs | 1 | 41 |
tokio-rs/tokio:tokio/src/task/consume_budget.rs:1 | use std::task::Poll;
/// Consumes a unit of budget and returns the execution back to the Tokio
/// runtime *if* the task's coop budget was exhausted.
///
/// The task will only yield if its entire coop budget has been exhausted.
/// This function can be used in order to insert optional yield points into long
/// compu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/consume_budget.rs | MIT | 53b586c5b9ca7805a1c66994962c62d874352590 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/53b586c5b9ca7805a1c66994962c62d874352590/tokio/src/task/consume_budget.rs | 1 | 41 |
tokio-rs/tokio:tokio/src/task/consume_budget.rs:1 | use std::task::Poll;
/// Consumes a unit of budget and returns the execution back to the Tokio
/// runtime *if* the task's coop budget was exhausted.
///
/// The task will only yield if its entire coop budget has been exhausted.
/// This function can be used in order to insert optional yield points into long
/// compu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/consume_budget.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/task/consume_budget.rs | 1 | 46 |
tokio-rs/tokio:tokio/src/task/consume_budget.rs:1 | use std::task::Poll;
/// Consumes a unit of budget and returns the execution back to the Tokio
/// runtime *if* the task's coop budget was exhausted.
///
/// The task will only yield if its entire coop budget has been exhausted.
/// This function can be used in order to insert optional yield points into long
/// compu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/consume_budget.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/task/consume_budget.rs | 1 | 45 |
tokio-rs/tokio:tokio/src/task/consume_budget.rs:1 | use std::task::Poll;
/// Consumes a unit of budget and returns the execution back to the Tokio
/// runtime *if* the task's coop budget was exhausted.
///
/// The task will only yield if its entire coop budget has been exhausted.
/// This function can be used in order to insert optional yield points into long
/// compu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/consume_budget.rs | MIT | f3e340a35b306e926e78537a0dd65b2e9b9cdc89 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f3e340a35b306e926e78537a0dd65b2e9b9cdc89/tokio/src/task/consume_budget.rs | 1 | 45 |
tokio-rs/tokio:tokio/src/task/consume_budget.rs:1 | use std::task::Poll;
/// Consumes a unit of budget and returns the execution back to the Tokio
/// runtime *if* the task's coop budget was exhausted.
///
/// The task will only yield if its entire coop budget has been exhausted.
/// This function can can be used in order to insert optional yield points into long
/// c... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/consume_budget.rs | MIT | 88e8c6239c0a4e51127c0f66c5ff3daf1f01564d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/88e8c6239c0a4e51127c0f66c5ff3daf1f01564d/tokio/src/task/consume_budget.rs | 1 | 45 |
tokio-rs/tokio:tokio/src/task/coop/consume_budget.rs:1 | /// Consumes a unit of budget and returns the execution back to the Tokio
/// runtime *if* the task's coop budget was exhausted.
///
/// The task will only yield if its entire coop budget has been exhausted.
/// This function can be used in order to insert optional yield points into long
/// computations that do not us... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/coop/consume_budget.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/task/coop/consume_budget.rs | 1 | 39 |
tokio-rs/tokio:tokio/src/task/coop/mod.rs:3 | //
// # Placing yield points
//
// Voluntary yield points should be placed _after_ at least some work has been
// done. If they are not, a future sufficiently deep in the task hierarchy may
// end up _never_ getting to run because of the number of yield points that
// inevitably appear before it is reached. In general,... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/coop/mod.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/task/coop/mod.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/task/coop/mod.rs:4 | Budget(None)
}
fn has_remaining(self) -> bool {
self.0.map_or(true, |budget| budget > 0)
}
}
/// Runs the given closure with a cooperative task budget. When the function
/// returns, the budget is reset to the value prior to calling the function.
#[inline(always)]
pub(crate) fn budget<R>(f: impl F... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/coop/mod.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/task/coop/mod.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/task/coop/mod.rs:6 | /// let delay = Pin::new(&mut this.delay);
///
/// // check if the future is ready
/// let had_budget_before = coop::has_budget_remaining();
/// if let Poll::Ready(v) = future.poll(cx) {
/// return Poll::Ready(Ok(v));
/// }
/// let has_budget_now = coop::has_b... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/coop/mod.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/task/coop/mod.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/task/coop/mod.rs:7 | context::budget(|cell| {
let prev = cell.get();
cell.set(Budget::unconstrained());
prev
}).unwrap_or(Budget::unconstrained())
}
}
cfg_coop! {
use pin_project_lite::pin_project;
use std::cell::Cell;
use std::future::Future;
use std::marker::PhantomData;
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/coop/mod.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/task/coop/mod.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/task/coop/mod.rs:9 | /// receiver: UnboundedReceiver<T>,
/// }
///
/// impl<T> Stream for CoopUnboundedReceiver<T> {
/// type Item = T;
/// fn poll_next(
/// mut self: Pin<&mut Self>,
/// cx: &mut Context<'_>
/// ) -> Poll<Option<T>> {
/// let coop = ready!(coop::po... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/coop/mod.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/task/coop/mod.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/task/coop/mod.rs:10 | Poll::Pending
}
}).unwrap_or(Poll::Ready(RestoreOnPending::new(Budget::unconstrained())))
}
/// Returns `Poll::Ready` if the current task has budget to consume, and `Poll::Pending` otherwise.
///
/// Note that in contrast to `poll_proceed`, this method does not consume any budget an... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/coop/mod.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/task/coop/mod.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/task/coop/mod.rs:11 | cfg_not_rt! {
#[inline(always)]
fn inc_budget_forced_yield_count() {}
fn register_waker(cx: &mut Context<'_>) {
cx.waker().wake_by_ref()
}
}
impl Budget {
/// Decrements the budget. Returns `true` if successful. Decrementing fails
/// when there is n... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/coop/mod.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/task/coop/mod.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/task/coop/mod.rs:12 | }
impl<F: Future> Future for Coop<F> {
type Output = F::Output;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let coop = ready!(poll_proceed(cx));
let me = self.project();
if let Poll::Ready(ret) = me.fut.poll(cx) {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/coop/mod.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/task/coop/mod.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/task/coop/mod.rs:13 | /// async fn receive_next<T>(receiver: &mut Receiver<T>) -> Option<T> {
/// // Use `StreamExt::next` to obtain a `Future` that resolves to the next value
/// let recv_future = receiver.next();
/// // Wrap it a cooperative wrapper
/// let coop_future = cooperative(recv_future);
/// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/coop/mod.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/task/coop/mod.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/task/coop/mod.rs:14 | let coop = assert_ready!(task::spawn(()).enter(|cx, _| poll_proceed(cx)));
assert_eq!(get().0.unwrap(), Budget::initial().0.unwrap() - 1);
drop(coop);
// we didn't make progress
assert_eq!(get().0, Budget::initial().0);
let coop = assert_ready!(task::spawn(()... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/coop/mod.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/task/coop/mod.rs | 521 | 573 |
tokio-rs/tokio:tokio/src/task/coop/mod.rs:15 | coop.made_progress();
}
let mut task = task::spawn(poll_fn(|cx| {
let coop = std::task::ready!(poll_proceed(cx));
coop.made_progress();
Poll::Ready(())
}));
assert_pending!(task.poll());
});
}
} | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/coop/mod.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/task/coop/mod.rs | 561 | 573 |
tokio-rs/tokio:tokio/src/task/coop/mod.rs:10 | /// let t = this.value.take();
/// // The latch made progress so call `made_progress` to ensure the budget
/// // is not reverted.
/// coop.made_progress();
/// Poll::Ready(t.unwrap())
/// } else {
/// // If the latc... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/coop/mod.rs | MIT | 611b7933561670c8349ddd5c100fdc76c474e3db | github | async-runtime | https://github.com/tokio-rs/tokio/blob/611b7933561670c8349ddd5c100fdc76c474e3db/tokio/src/task/coop/mod.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/task/coop/mod.rs:11 | /// Returns `Poll::Ready` if the current task has budget to consume, and `Poll::Pending` otherwise.
///
/// Note that in contrast to `poll_proceed`, this method does not consume any budget and is used when
/// polling for budget availability.
#[inline]
pub(crate) fn poll_budget_available(cx: &mut Co... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/coop/mod.rs | MIT | 611b7933561670c8349ddd5c100fdc76c474e3db | github | async-runtime | https://github.com/tokio-rs/tokio/blob/611b7933561670c8349ddd5c100fdc76c474e3db/tokio/src/task/coop/mod.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/task/coop/mod.rs:12 | fn register_waker(cx: &mut Context<'_>) {
cx.waker().wake_by_ref()
}
}
impl Budget {
/// Decrements the budget. Returns `true` if successful. Decrementing fails
/// when there is not enough remaining budget.
fn decrement(&mut self) -> BudgetDecrement {
if... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/coop/mod.rs | MIT | 611b7933561670c8349ddd5c100fdc76c474e3db | github | async-runtime | https://github.com/tokio-rs/tokio/blob/611b7933561670c8349ddd5c100fdc76c474e3db/tokio/src/task/coop/mod.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/task/coop/mod.rs:13 | fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let coop = ready!(poll_proceed(cx));
let me = self.project();
if let Poll::Ready(ret) = me.fut.poll(cx) {
coop.made_progress();
Poll::Ready(ret)
} else {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/coop/mod.rs | MIT | 611b7933561670c8349ddd5c100fdc76c474e3db | github | async-runtime | https://github.com/tokio-rs/tokio/blob/611b7933561670c8349ddd5c100fdc76c474e3db/tokio/src/task/coop/mod.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/task/coop/mod.rs:14 | /// let coop_future = cooperative(recv_future);
/// // And await
/// coop_future.await
/// }
#[inline]
pub fn cooperative<F: Future>(fut: F) -> Coop<F> {
Coop { fut }
}
}
#[cfg(all(test, not(loom)))]
mod test {
use super::*;
#[cfg(all(target_family = "wasm", not(tar... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/coop/mod.rs | MIT | 611b7933561670c8349ddd5c100fdc76c474e3db | github | async-runtime | https://github.com/tokio-rs/tokio/blob/611b7933561670c8349ddd5c100fdc76c474e3db/tokio/src/task/coop/mod.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/task/coop/mod.rs:15 | // we didn't make progress
assert_eq!(get().0, Budget::initial().0);
let coop = assert_ready!(task::spawn(()).enter(|cx, _| poll_proceed(cx)));
assert_eq!(get().0.unwrap(), Budget::initial().0.unwrap() - 1);
coop.made_progress();
drop(coop);
// we... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/coop/mod.rs | MIT | 611b7933561670c8349ddd5c100fdc76c474e3db | github | async-runtime | https://github.com/tokio-rs/tokio/blob/611b7933561670c8349ddd5c100fdc76c474e3db/tokio/src/task/coop/mod.rs | 561 | 609 |
tokio-rs/tokio:tokio/src/task/coop/mod.rs:6 | /// let delay = Pin::new(&mut this.delay);
///
/// // check if the future is ready
/// let had_budget_before = coop::has_budget_remaining();
/// if let Poll::Ready(v) = future.poll(cx) {
/// return Poll::Ready(Ok(v));
/// }
/// let has_budget_now = coop::has_b... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/coop/mod.rs | MIT | 0284d1b5c8ea5aff5b30c254200fb0a46c21d67c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0284d1b5c8ea5aff5b30c254200fb0a46c21d67c/tokio/src/task/coop/mod.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/task/coop/mod.rs:7 | context::budget(|cell| {
let prev = cell.get();
cell.set(Budget::unconstrained());
prev
}).unwrap_or(Budget::unconstrained())
}
}
cfg_coop! {
use pin_project_lite::pin_project;
use std::cell::Cell;
use std::future::Future;
use std::pin::Pin;
use std::... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/coop/mod.rs | MIT | 0284d1b5c8ea5aff5b30c254200fb0a46c21d67c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0284d1b5c8ea5aff5b30c254200fb0a46c21d67c/tokio/src/task/coop/mod.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/task/coop/mod.rs:8 | /// progress is made every time a task is polled, the budget is automatically restored to its
/// former value if the returned `RestoreOnPending` is dropped. It is the caller's
/// responsibility to call `RestoreOnPending::made_progress` if it made progress, to ensure
/// that the budget empties appropriate... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/coop/mod.rs | MIT | 0284d1b5c8ea5aff5b30c254200fb0a46c21d67c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0284d1b5c8ea5aff5b30c254200fb0a46c21d67c/tokio/src/task/coop/mod.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/task/coop/mod.rs:9 | Poll::Ready(())
} else {
register_waker(cx);
Poll::Pending
}
}
cfg_rt! {
cfg_unstable_metrics! {
#[inline(always)]
fn inc_budget_forced_yield_count() {
let _ = context::with_current(|handle| {
handle.sc... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/coop/mod.rs | MIT | 0284d1b5c8ea5aff5b30c254200fb0a46c21d67c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0284d1b5c8ea5aff5b30c254200fb0a46c21d67c/tokio/src/task/coop/mod.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/task/coop/mod.rs:10 | fn decrement(&mut self) -> BudgetDecrement {
if let Some(num) = &mut self.0 {
if *num > 0 {
*num -= 1;
let hit_zero = *num == 0;
BudgetDecrement { success: true, hit_zero }
} else {
BudgetDecrem... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/coop/mod.rs | MIT | 0284d1b5c8ea5aff5b30c254200fb0a46c21d67c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0284d1b5c8ea5aff5b30c254200fb0a46c21d67c/tokio/src/task/coop/mod.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/task/coop/mod.rs:11 | let coop = ready!(poll_proceed(cx));
let me = self.project();
if let Poll::Ready(ret) = me.fut.poll(cx) {
coop.made_progress();
Poll::Ready(ret)
} else {
Poll::Pending
}
}
}
/// Run a future with a budget co... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/coop/mod.rs | MIT | 0284d1b5c8ea5aff5b30c254200fb0a46c21d67c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0284d1b5c8ea5aff5b30c254200fb0a46c21d67c/tokio/src/task/coop/mod.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/task/coop/mod.rs:12 | assert!(get().0.is_none());
drop(coop);
assert!(get().0.is_none());
budget(|| {
assert_eq!(get().0, Budget::initial().0);
let coop = assert_ready!(task::spawn(()).enter(|cx, _| poll_proceed(cx)));
assert_eq!(get().0.unwrap(), Budget::initial().0.unwrap() - 1... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/coop/mod.rs | MIT | 0284d1b5c8ea5aff5b30c254200fb0a46c21d67c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0284d1b5c8ea5aff5b30c254200fb0a46c21d67c/tokio/src/task/coop/mod.rs | 441 | 499 |
tokio-rs/tokio:tokio/src/task/coop/mod.rs:13 | budget(|| {
let n = get().0.unwrap();
for _ in 0..n {
let coop = assert_ready!(task::spawn(()).enter(|cx, _| poll_proceed(cx)));
coop.made_progress();
}
let mut task = task::spawn(poll_fn(|cx| {
let coop = std::task::ready... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/coop/mod.rs | MIT | 0284d1b5c8ea5aff5b30c254200fb0a46c21d67c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0284d1b5c8ea5aff5b30c254200fb0a46c21d67c/tokio/src/task/coop/mod.rs | 481 | 499 |
tokio-rs/tokio:tokio/src/task/coop/mod.rs:8 | /// progress is made every time a task is polled, the budget is automatically restored to its
/// former value if the returned `RestoreOnPending` is dropped. It is the caller's
/// responsibility to call `RestoreOnPending::made_progress` if it made progress, to ensure
/// that the budget empties appropriate... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/coop/mod.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/src/task/coop/mod.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/task/coop/mod.rs:9 | }
}
cfg_not_unstable_metrics! {
#[inline(always)]
fn inc_budget_forced_yield_count() {}
}
fn defer(cx: &mut Context<'_>) {
context::defer(cx.waker());
}
}
cfg_not_rt! {
#[inline(always)]
fn inc_budget_forced_yield_cou... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/coop/mod.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/src/task/coop/mod.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/task/coop/mod.rs:10 | fn is_unconstrained(self) -> bool {
self.0.is_none()
}
}
pin_project! {
/// Future wrapper to ensure cooperative scheduling.
///
/// When being polled `poll_proceed` is called before the inner future is polled to check
/// if the inner future has exceeded its... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/coop/mod.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/src/task/coop/mod.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/task/coop/mod.rs:11 | pub(crate) fn cooperative<F: Future>(fut: F) -> Coop<F> {
Coop { fut }
}
}
#[cfg(all(test, not(loom)))]
mod test {
use super::*;
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
use wasm_bindgen_test::wasm_bindgen_test as test;
fn get() -> Budget {
context::budget(|cel... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/coop/mod.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/src/task/coop/mod.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/task/coop/mod.rs:12 | coop.made_progress();
drop(coop);
// we _did_ make progress
assert_eq!(get().0.unwrap(), Budget::initial().0.unwrap() - 1);
let coop = assert_ready!(task::spawn(()).enter(|cx, _| poll_proceed(cx)));
assert_eq!(get().0.unwrap(), Budget::initial().0.unwrap() - ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/coop/mod.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/src/task/coop/mod.rs | 441 | 484 |
tokio-rs/tokio:tokio/src/task/coop/unconstrained.rs:1 | use pin_project_lite::pin_project;
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};
pin_project! {
/// Future for the [`unconstrained`](unconstrained) method.
#[cfg_attr(docsrs, doc(cfg(feature = "rt")))]
#[must_use = "Unconstrained does nothing unless polled"]
pub struct Unc... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/coop/unconstrained.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/task/coop/unconstrained.rs | 1 | 45 |
tokio-rs/tokio:tokio/src/task/core.rs:1 | use crate::loom::alloc::Track;
use crate::loom::cell::CausalCell;
use crate::task::raw::{self, Vtable};
use crate::task::state::State;
use crate::task::waker::waker_ref;
use crate::task::Schedule;
use std::cell::UnsafeCell;
use std::future::Future;
use std::mem::MaybeUninit;
use std::pin::Pin;
use std::ptr::{self, Non... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/core.rs | MIT | f9ddb93604a830d106475bd4c4cae436fafcc0da | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f9ddb93604a830d106475bd4c4cae436fafcc0da/tokio/src/task/core.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/task/core.rs:2 | /// Task state
pub(super) state: State,
/// Pointer to the executor owned by the task
pub(super) executor: CausalCell<Option<NonNull<()>>>,
/// Pointer to next task, used for misc task linked lists.
pub(crate) queue_next: UnsafeCell<*const Header>,
/// Pointer to the next task in the ownershi... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/core.rs | MIT | f9ddb93604a830d106475bd4c4cae436fafcc0da | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f9ddb93604a830d106475bd4c4cae436fafcc0da/tokio/src/task/core.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/task/core.rs:3 | where
S: Schedule,
{
Box::new(Cell {
header: Header {
state,
executor: CausalCell::new(None),
queue_next: UnsafeCell::new(ptr::null()),
owned_next: UnsafeCell::new(None),
owned_prev: UnsafeCell::new(None),
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/core.rs | MIT | f9ddb93604a830d106475bd4c4cae436fafcc0da | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f9ddb93604a830d106475bd4c4cae436fafcc0da/tokio/src/task/core.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/task/core.rs:4 | let future = unsafe { Pin::new_unchecked(future) };
// The waker passed into the `poll` function does not require a ref
// count increment.
let waker_ref = waker_ref::<T, S>(header);
let mut cx = Context::from_waker(&*waker_ref);
future.poll(&mut cx)
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/core.rs | MIT | f9ddb93604a830d106475bd4c4cae436fafcc0da | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f9ddb93604a830d106475bd4c4cae436fafcc0da/tokio/src/task/core.rs | 121 | 156 |
tokio-rs/tokio:tokio/src/task/error.rs:1 | use std::any::Any;
use std::fmt;
use std::io;
use std::sync::Mutex;
doc_rt_core! {
/// Task failed to execute to completion.
pub struct JoinError {
repr: Repr,
}
}
enum Repr {
Cancelled,
Panic(Mutex<Box<dyn Any + Send + 'static>>),
}
impl JoinError {
#[doc(hidden)]
#[deprecated]
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/error.rs | MIT | 968c143acdde1905219880ba662cecb58c4aa82d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/968c143acdde1905219880ba662cecb58c4aa82d/tokio/src/task/error.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/task/error.rs:2 | }
/// Returns true if the error was caused by the task being cancelled
pub fn is_cancelled(&self) -> bool {
match &self.repr {
Repr::Cancelled => true,
_ => false,
}
}
/// Returns true if the error was caused by the task panicking
///
/// # Examples
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/error.rs | MIT | 968c143acdde1905219880ba662cecb58c4aa82d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/968c143acdde1905219880ba662cecb58c4aa82d/tokio/src/task/error.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/task/error.rs:3 | ///
/// # Examples
///
/// ```should_panic
/// use std::panic;
///
/// #[tokio::main]
/// async fn main() {
/// let err = tokio::spawn(async {
/// panic!("boom");
/// }).await.unwrap_err();
///
/// if err.is_panic() {
/// // Resume the pani... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/error.rs | MIT | 968c143acdde1905219880ba662cecb58c4aa82d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/968c143acdde1905219880ba662cecb58c4aa82d/tokio/src/task/error.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/task/error.rs:4 | /// panic::resume_unwind(reason);
/// }
/// }
/// ```
pub fn try_into_panic(self) -> Result<Box<dyn Any + Send + 'static>, JoinError> {
match self.repr {
Repr::Panic(p) => Ok(p.into_inner().expect("Extracting panic from mutex")),
_ => Err(self),
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/error.rs | MIT | 968c143acdde1905219880ba662cecb58c4aa82d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/968c143acdde1905219880ba662cecb58c4aa82d/tokio/src/task/error.rs | 121 | 163 |
tokio-rs/tokio:tokio/src/task/error.rs:1 | use std::any::Any;
use std::fmt;
use std::io;
use std::sync::Mutex;
doc_rt_core! {
/// Task failed to execute to completion.
pub struct JoinError {
repr: Repr,
}
}
enum Repr {
Cancelled,
Panic(Mutex<Box<dyn Any + Send + 'static>>),
}
impl JoinError {
#[doc(hidden)]
#[deprecated]
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/error.rs | MIT | cbe369a3ed5c252ca7581e37986dc912d88e58c6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cbe369a3ed5c252ca7581e37986dc912d88e58c6/tokio/src/task/error.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/task/error.rs:2 | }
}
impl fmt::Display for JoinError {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self.repr {
Repr::Cancelled => write!(fmt, "cancelled"),
Repr::Panic(_) => write!(fmt, "panic"),
}
}
}
impl fmt::Debug for JoinError {
fn fmt(&self, fmt: &mut f... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/error.rs | MIT | cbe369a3ed5c252ca7581e37986dc912d88e58c6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cbe369a3ed5c252ca7581e37986dc912d88e58c6/tokio/src/task/error.rs | 41 | 74 |
tokio-rs/tokio:tokio/src/task/error.rs:1 | use std::any::Any;
use std::fmt;
use std::io;
doc_rt_core! {
/// Task failed to execute to completion.
pub struct JoinError {
repr: Repr,
}
}
enum Repr {
Cancelled,
Panic(Box<dyn Any + Send + 'static>),
}
impl JoinError {
/// Create a new `cancelled` error
pub fn cancelled() -> Jo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/error.rs | MIT | 8b60c5386a60be4dacffe71823350040e8ba90fd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8b60c5386a60be4dacffe71823350040e8ba90fd/tokio/src/task/error.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/task/error.rs:2 | impl fmt::Debug for JoinError {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self.repr {
Repr::Cancelled => write!(fmt, "JoinError::Cancelled"),
Repr::Panic(_) => write!(fmt, "JoinError::Panic(...)"),
}
}
}
impl std::error::Error for JoinError {}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/error.rs | MIT | 8b60c5386a60be4dacffe71823350040e8ba90fd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8b60c5386a60be4dacffe71823350040e8ba90fd/tokio/src/task/error.rs | 41 | 63 |
tokio-rs/tokio:tokio/src/task/harness.rs:1 | use crate::loom::alloc::Track;
use crate::task::core::{Cell, Core, Header, Trailer};
use crate::task::state::Snapshot;
use crate::task::{JoinError, Schedule, Task};
use std::future::Future;
use std::marker::PhantomData;
use std::mem::{ManuallyDrop, MaybeUninit};
use std::ptr::NonNull;
use std::task::{Poll, Waker};
//... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/harness.rs | MIT | 560d0fa548314e223601ed83429daf237d72afbd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/560d0fa548314e223601ed83429daf237d72afbd/tokio/src/task/harness.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/task/harness.rs:2 | unsafe { &mut self.cell.as_mut().core }
}
}
impl<T, S> Harness<T, S>
where
T: Future,
S: Schedule,
{
/// Polls the inner future.
///
/// All necessary state checks and transitions are performed.
///
/// Panics raised while polling the future are handled.
///
/// Returns `true` i... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/harness.rs | MIT | 560d0fa548314e223601ed83429daf237d72afbd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/560d0fa548314e223601ed83429daf237d72afbd/tokio/src/task/harness.rs | 41 | 100 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.