Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions futures-executor/tests/local_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn run_until_single_future() {
{
let mut pool = LocalPool::new();
let mut exec = pool.executor();
let fut = lazy(|| {
let fut = lazy(|_| {
cnt += 1;
DONE
});
Expand All @@ -55,15 +55,15 @@ fn run_until_ignores_spawned() {
let mut pool = LocalPool::new();
let mut exec = pool.executor();
exec.spawn_local(Box::new(pending())).unwrap();
pool.run_until(lazy(|| DONE), &mut exec).unwrap();
pool.run_until(lazy(|_| DONE), &mut exec).unwrap();
}

#[test]
fn run_until_executes_spawned() {
let (tx, rx) = oneshot::channel();
let mut pool = LocalPool::new();
let mut exec = pool.executor();
exec.spawn_local(Box::new(lazy(move || {
exec.spawn_local(Box::new(lazy(move |_| {
tx.send(()).unwrap();
DONE
}))).unwrap();
Expand All @@ -79,8 +79,8 @@ fn run_executes_spawned() {
let mut exec = pool.executor();
let mut exec2 = pool.executor();

exec.spawn_local(Box::new(lazy(move || {
exec2.spawn_local(Box::new(lazy(move || {
exec.spawn_local(Box::new(lazy(move |_| {
exec2.spawn_local(Box::new(lazy(move |_| {
cnt2.set(cnt2.get() + 1);
DONE
}))).unwrap();
Expand All @@ -103,7 +103,7 @@ fn run_spawn_many() {

for _ in 0..ITER {
let cnt = cnt.clone();
exec.spawn_local(Box::new(lazy(move || {
exec.spawn_local(Box::new(lazy(move |_| {
cnt.set(cnt.get() + 1);
DONE
}))).unwrap();
Expand All @@ -120,7 +120,7 @@ fn nesting_run() {
let mut pool = LocalPool::new();
let mut exec = pool.executor();

exec.spawn(Box::new(lazy(|| {
exec.spawn(Box::new(lazy(|_| {
let mut pool = LocalPool::new();
let mut exec = pool.executor();
pool.run(&mut exec);
Expand Down
16 changes: 8 additions & 8 deletions futures-util/src/future/lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ enum _Lazy<R, F> {
/// use futures::future::{self, FutureResult};
///
/// # fn main() {
/// let a = future::lazy(|| future::ok::<u32, u32>(1));
/// let a = future::lazy(|_| future::ok::<u32, u32>(1));
///
/// let b = future::lazy(|| -> FutureResult<u32, u32> {
/// let b = future::lazy(|_| -> FutureResult<u32, u32> {
/// panic!("oh no!")
/// });
/// drop(b); // closure is never run
/// # }
/// ```
pub fn lazy<R, F>(f: F) -> Lazy<R, F>
where F: FnOnce() -> R,
where F: FnOnce(&mut task::Context) -> R,
R: IntoFuture
{
Lazy {
Expand All @@ -55,17 +55,17 @@ pub fn lazy<R, F>(f: F) -> Lazy<R, F>
}

impl<R, F> Lazy<R, F>
where F: FnOnce() -> R,
where F: FnOnce(&mut task::Context) -> R,
R: IntoFuture,
{
fn get(&mut self) -> &mut R::Future {
fn get(&mut self, cx: &mut task::Context) -> &mut R::Future {
match self.inner {
_Lazy::First(_) => {}
_Lazy::Second(ref mut f) => return f,
_Lazy::Moved => panic!(), // can only happen if `f()` panics
}
match mem::replace(&mut self.inner, _Lazy::Moved) {
_Lazy::First(f) => self.inner = _Lazy::Second(f().into_future()),
_Lazy::First(f) => self.inner = _Lazy::Second(f(cx).into_future()),
_ => panic!(), // we already found First
}
match self.inner {
Expand All @@ -76,13 +76,13 @@ impl<R, F> Lazy<R, F>
}

impl<R, F> Future for Lazy<R, F>
where F: FnOnce() -> R,
where F: FnOnce(&mut task::Context) -> R,
R: IntoFuture,
{
type Item = R::Item;
type Error = R::Error;

fn poll(&mut self, cx: &mut task::Context) -> Poll<R::Item, R::Error> {
self.get().poll(cx)
self.get(cx).poll(cx)
}
}
2 changes: 1 addition & 1 deletion futures-util/src/future/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ pub trait FutureExt: Future {
/// let mut future = future::ok::<i32, u32>(2);
/// assert!(block_on(future.catch_unwind()).is_ok());
///
/// let mut future = future::lazy(|| -> FutureResult<i32, u32> {
/// let mut future = future::lazy(|_| -> FutureResult<i32, u32> {
/// panic!();
/// future::ok::<i32, u32>(2)
/// });
Expand Down
2 changes: 1 addition & 1 deletion futures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub mod executor {
//! ```
//! use futures::executor::ThreadPool;
//! # use futures::future::{Future, lazy};
//! # let my_app: Box<Future<Item = (), Error = ()>> = Box::new(lazy(|| Ok(())));
//! # let my_app: Box<Future<Item = (), Error = ()>> = Box::new(lazy(|_| Ok(())));
//!
//! // assumping `my_app: Future`
//! ThreadPool::new().run(my_app);
Expand Down
2 changes: 1 addition & 1 deletion tests/bilock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use support::*;

#[test]
fn smoke() {
let future = future::lazy(|| {
let future = future::lazy(|_| {
let (a, b) = BiLock::new(1);

{
Expand Down
8 changes: 4 additions & 4 deletions tests/ready_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl AssertSendSync for FuturesUnordered<()> {}

#[test]
fn basic_usage() {
future::lazy(move || {
future::lazy(move |_| {
let mut queue = FuturesUnordered::new();
let (tx1, rx1) = oneshot::channel();
let (tx2, rx2) = oneshot::channel();
Expand Down Expand Up @@ -43,7 +43,7 @@ fn basic_usage() {

#[test]
fn resolving_errors() {
future::lazy(move || {
future::lazy(move |_| {
let mut queue = FuturesUnordered::new();
let (tx1, rx1) = oneshot::channel();
let (tx2, rx2) = oneshot::channel();
Expand Down Expand Up @@ -73,7 +73,7 @@ fn resolving_errors() {

#[test]
fn dropping_ready_queue() {
future::lazy(move || {
future::lazy(move |_| {
let mut queue = FuturesUnordered::new();
let (mut tx1, rx1) = oneshot::channel::<()>();
let (mut tx2, rx2) = oneshot::channel::<()>();
Expand Down Expand Up @@ -148,7 +148,7 @@ fn stress() {

#[test]
fn panicking_future_dropped() {
future::lazy(move || {
future::lazy(move |_| {
let mut queue = FuturesUnordered::new();
queue.push(future::poll_fn(|| -> Poll<i32, i32> {
panic!()
Expand Down
2 changes: 1 addition & 1 deletion tests/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ fn recursive_poll_with_unpark() {
let f1 = run_stream.shared();
let f2 = f1.clone();
let f3 = f1.clone();
tx0.unbounded_send(Box::new(future::lazy(move || {
tx0.unbounded_send(Box::new(future::lazy(move |_| {
task::current().notify();
f1.map(|_|()).map_err(|_|())
.select(rx1.map_err(|_|()))
Expand Down
2 changes: 1 addition & 1 deletion tests/sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl<S: Sink> Future for StartSendFut<S> {
fn mpsc_blocking_start_send() {
let (mut tx, mut rx) = mpsc::channel::<i32>(0);

futures::future::lazy(|| {
futures::future::lazy(|_| {
assert_eq!(tx.start_send(0).unwrap(), AsyncSink::Ready);

let flag = Flag::new();
Expand Down