Skip to content

Commit

Permalink
Fix CI and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
LucioFranco committed Aug 27, 2020
1 parent 800322b commit cad3760
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 38 deletions.
4 changes: 2 additions & 2 deletions tokio/src/io/poll_evented.rs
Expand Up @@ -173,7 +173,7 @@ where
///
/// The runtime is usually set implicitly when this function is called
/// from a future driven by a tokio runtime, otherwise runtime can be set
/// explicitly with [`Handle::enter`](crate::runtime::Handle::enter) function.
/// explicitly with [`Runtime::enter`](crate::runtime::Runtime::enter) function.
pub fn new(io: E) -> io::Result<Self> {
PollEvented::new_with_ready(io, mio::Ready::all())
}
Expand Down Expand Up @@ -201,7 +201,7 @@ where
///
/// The runtime is usually set implicitly when this function is called
/// from a future driven by a tokio runtime, otherwise runtime can be set
/// explicitly with [`Handle::enter`](crate::runtime::Handle::enter) function.
/// explicitly with [`Runtime::enter`](crate::runtime::Runtime::enter) function.
pub fn new_with_ready(io: E, ready: mio::Ready) -> io::Result<Self> {
let registration = Registration::new_with_ready(&io, ready)?;
Ok(Self {
Expand Down
4 changes: 2 additions & 2 deletions tokio/src/io/registration.rs
Expand Up @@ -67,7 +67,7 @@ impl Registration {
///
/// The runtime is usually set implicitly when this function is called
/// from a future driven by a tokio runtime, otherwise runtime can be set
/// explicitly with [`Handle::enter`](crate::runtime::Handle::enter) function.
/// explicitly with [`Runtime::enter`](crate::runtime::Runtime::enter) function.
pub fn new<T>(io: &T) -> io::Result<Registration>
where
T: Evented,
Expand Down Expand Up @@ -104,7 +104,7 @@ impl Registration {
///
/// The runtime is usually set implicitly when this function is called
/// from a future driven by a tokio runtime, otherwise runtime can be set
/// explicitly with [`Handle::enter`](crate::runtime::Handle::enter) function.
/// explicitly with [`Runtime::enter`](crate::runtime::Runtime::enter) function.
pub fn new_with_ready<T>(io: &T, ready: mio::Ready) -> io::Result<Registration>
where
T: Evented,
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/net/tcp/listener.rs
Expand Up @@ -262,7 +262,7 @@ impl TcpListener {
///
/// The runtime is usually set implicitly when this function is called
/// from a future driven by a tokio runtime, otherwise runtime can be set
/// explicitly with [`Handle::enter`](crate::runtime::Handle::enter) function.
/// explicitly with [`Runtime::enter`](crate::runtime::Runtime::enter) function.
pub fn from_std(listener: net::TcpListener) -> io::Result<TcpListener> {
let io = mio::net::TcpListener::from_std(listener)?;
let io = PollEvented::new(io)?;
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/net/tcp/stream.rs
Expand Up @@ -187,7 +187,7 @@ impl TcpStream {
///
/// The runtime is usually set implicitly when this function is called
/// from a future driven by a tokio runtime, otherwise runtime can be set
/// explicitly with [`Handle::enter`](crate::runtime::Handle::enter) function.
/// explicitly with [`Runtime::enter`](crate::runtime::Runtime::enter) function.
pub fn from_std(stream: net::TcpStream) -> io::Result<TcpStream> {
let io = mio::net::TcpStream::from_stream(stream)?;
let io = PollEvented::new(io)?;
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/net/udp/socket.rs
Expand Up @@ -64,7 +64,7 @@ impl UdpSocket {
///
/// The runtime is usually set implicitly when this function is called
/// from a future driven by a tokio runtime, otherwise runtime can be set
/// explicitly with [`Handle::enter`](crate::runtime::Handle::enter) function.
/// explicitly with [`Runtime::enter`](crate::runtime::Runtime::enter) function.
pub fn from_std(socket: net::UdpSocket) -> io::Result<UdpSocket> {
let io = mio::net::UdpSocket::from_socket(socket)?;
let io = PollEvented::new(io)?;
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/net/unix/datagram/socket.rs
Expand Up @@ -164,7 +164,7 @@ impl UnixDatagram {
///
/// The runtime is usually set implicitly when this function is called
/// from a future driven by a Tokio runtime, otherwise runtime can be set
/// explicitly with [`Handle::enter`](crate::runtime::Handle::enter) function.
/// explicitly with [`Runtime::enter`](crate::runtime::Runtime::enter) function.
/// # Examples
/// ```
/// # use std::error::Error;
Expand Down
4 changes: 2 additions & 2 deletions tokio/src/net/unix/listener.rs
Expand Up @@ -60,7 +60,7 @@ impl UnixListener {
///
/// The runtime is usually set implicitly when this function is called
/// from a future driven by a tokio runtime, otherwise runtime can be set
/// explicitly with [`Handle::enter`](crate::runtime::Handle::enter) function.
/// explicitly with [`Runtime::enter`](crate::runtime::Runtime::enter) function.
pub fn bind<P>(path: P) -> io::Result<UnixListener>
where
P: AsRef<Path>,
Expand All @@ -82,7 +82,7 @@ impl UnixListener {
///
/// The runtime is usually set implicitly when this function is called
/// from a future driven by a tokio runtime, otherwise runtime can be set
/// explicitly with [`Handle::enter`](crate::runtime::Handle::enter) function.
/// explicitly with [`Runtime::enter`](crate::runtime::Runtime::enter) function.
pub fn from_std(listener: net::UnixListener) -> io::Result<UnixListener> {
let listener = mio_uds::UnixListener::from_listener(listener)?;
let io = PollEvented::new(listener)?;
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/net/unix/stream.rs
Expand Up @@ -54,7 +54,7 @@ impl UnixStream {
///
/// The runtime is usually set implicitly when this function is called
/// from a future driven by a tokio runtime, otherwise runtime can be set
/// explicitly with [`Handle::enter`](crate::runtime::Handle::enter) function.
/// explicitly with [`Runtime::enter`](crate::runtime::Runtime::enter) function.
pub fn from_std(stream: net::UnixStream) -> io::Result<UnixStream> {
let stream = mio_uds::UnixStream::from_stream(stream)?;
let io = PollEvented::new(stream)?;
Expand Down
5 changes: 3 additions & 2 deletions tokio/src/runtime/blocking/pool.rs
Expand Up @@ -6,6 +6,7 @@ use crate::runtime::blocking::schedule::NoopSchedule;
use crate::runtime::blocking::shutdown;
use crate::runtime::blocking::task::BlockingTask;
use crate::runtime::builder::ThreadNameFn;
use crate::runtime::context;
use crate::runtime::task::{self, JoinHandle};
use crate::runtime::{Builder, Callback, Handle};

Expand Down Expand Up @@ -67,7 +68,7 @@ pub(crate) fn spawn_blocking<F, R>(func: F) -> JoinHandle<R>
where
F: FnOnce() -> R + Send + 'static,
{
let rt = Handle::current();
let rt = context::current().expect("not currently running on the Tokio runtime.");

let (task, handle) = task::joinable(BlockingTask::new(func));
let _ = rt.blocking_spawner.spawn(task, &rt);
Expand All @@ -79,7 +80,7 @@ pub(crate) fn try_spawn_blocking<F, R>(func: F) -> Result<(), ()>
where
F: FnOnce() -> R + Send + 'static,
{
let rt = Handle::current();
let rt = context::current().expect("not currently running on the Tokio runtime.");

let (task, _handle) = task::joinable(BlockingTask::new(func));
rt.blocking_spawner.spawn(task, &rt)
Expand Down
8 changes: 4 additions & 4 deletions tokio/src/runtime/builder.rs
Expand Up @@ -67,7 +67,7 @@ pub struct Builder {
pub(super) before_stop: Option<Callback>,
}

pub(crate) type ThreadNameFn = Arc<dyn Fn() -> String + Send + Sync + 'static>;
pub(crate) type ThreadNameFn = std::sync::Arc<dyn Fn() -> String + Send + Sync + 'static>;

#[derive(Debug, Clone, Copy)]
enum Kind {
Expand Down Expand Up @@ -100,7 +100,7 @@ impl Builder {
max_threads: 512,

// Default thread name
thread_name: Arc::new(|| "tokio-runtime-worker".into()),
thread_name: std::sync::Arc::new(|| "tokio-runtime-worker".into()),

// Do not set a stack size by default
thread_stack_size: None,
Expand Down Expand Up @@ -212,7 +212,7 @@ impl Builder {
/// ```
pub fn thread_name(&mut self, val: impl Into<String>) -> &mut Self {
let val = val.into();
self.thread_name = Arc::new(move || val.clone());
self.thread_name = std::sync::Arc::new(move || val.clone());
self
}

Expand Down Expand Up @@ -240,7 +240,7 @@ impl Builder {
where
F: Fn() -> String + Send + Sync + 'static,
{
self.thread_name = Arc::new(f);
self.thread_name = std::sync::Arc::new(f);
self
}

Expand Down
6 changes: 4 additions & 2 deletions tokio/src/runtime/context.rs
Expand Up @@ -7,8 +7,10 @@ thread_local! {
static CONTEXT: RefCell<Option<Handle>> = RefCell::new(None)
}

pub(crate) fn current() -> Option<Handle> {
CONTEXT.with(|ctx| ctx.borrow().clone())
cfg_blocking_impl! {
pub(crate) fn current() -> Option<Handle> {
CONTEXT.with(|ctx| ctx.borrow().clone())
}
}

cfg_io_driver! {
Expand Down
11 changes: 0 additions & 11 deletions tokio/src/runtime/handle.rs
Expand Up @@ -33,15 +33,4 @@ impl Handle {
{
context::enter(self.clone(), f)
}

/// Returns a `Handle` view over the currently running `Runtime`
///
/// # Panic
///
/// This will panic if called outside the context of a Tokio runtime. That means that you must
/// call this on one of the threads **being run by the runtime**. Calling this from within a
/// thread created by `std::thread::spawn` (for example) will cause a panic.
pub(crate) fn current() -> Self {
context::current().expect("not currently running on the Tokio runtime.")
}
}
11 changes: 4 additions & 7 deletions tokio/src/runtime/mod.rs
Expand Up @@ -409,10 +409,10 @@ impl Runtime {
/// complete, and yielding its resolved result. Any tasks or timers which
/// the future spawns internally will be executed on the runtime.
///
/// `&mut` is required as calling `block_on` **may** result in advancing the
/// state of the runtime. The details depend on how the runtime is
/// configured. [`runtime::Handle::block_on`][handle] provides a version
/// that takes `&self`.
/// When this runtime is configured with `core_threads = 0` only the first call
/// to `block_on` will run the io/timer driver. All other calls _before_ the first
/// `block_on` completes will just hook into that driver. This means the driver
/// may be passed around from thread to thread manually by the user.
///
/// This method may not be called from an asynchronous context.
///
Expand Down Expand Up @@ -477,11 +477,8 @@ impl Runtime {
/// have an executor available on creation such as [`Delay`] or [`TcpStream`].
/// It will also allow you to call methods such as [`tokio::spawn`].
///
/// This function is also available as [`Handle::enter`].
///
/// [`Delay`]: struct@crate::time::Delay
/// [`TcpStream`]: struct@crate::net::TcpStream
/// [`Handle::enter`]: fn@crate::runtime::Handle::enter
/// [`tokio::spawn`]: fn@crate::spawn
///
/// # Example
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/task/spawn.rs
Expand Up @@ -18,7 +18,7 @@ doc_rt_core! {
///
/// This function must be called from the context of a Tokio runtime. Tasks running on
/// the Tokio runtime are always inside its context, but you can also enter the context
/// using the [`Handle::enter`](crate::runtime::Handle::enter()) method.
/// using the [`Runtime::enter`](crate::runtime::Runtime::enter()) method.
///
/// # Examples
///
Expand Down

0 comments on commit cad3760

Please sign in to comment.