Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

update futures dependency to 0.3 #19

Merged
merged 2 commits into from
Jan 18, 2020
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
6 changes: 3 additions & 3 deletions async-coap-tokio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ readme = "README.md"

[dependencies]
async-coap = { path = "../async-coap", version = "0.1" }
tokio-net = "0.2.0-alpha.4"
tokio = {version = "0.2", features = ["net"]}
mio = "0.6"
futures-preview = { version = "=0.3.0-alpha.18", features = ["async-await", "nightly"] }
futures = "0.3"

[dev-dependencies]
tokio = "0.2.0-alpha.4"
tokio = {version = "0.2", features = ["rt-core", "macros"]}
2 changes: 1 addition & 1 deletion async-coap-tokio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
//! use async_coap_tokio::TokioAsyncUdpSocket;
//! use futures::prelude::*;
//! use std::sync::Arc;
//! use tokio::executor::spawn;
//! use tokio::spawn;
//!
//! #[tokio::main]
//! async fn main() {
Expand Down
6 changes: 3 additions & 3 deletions async-coap-tokio/src/tokio_async_udp_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ use async_coap::datagram::{
AsyncDatagramSocket, AsyncRecvFrom, AsyncSendTo, DatagramSocketTypes, MulticastSocket,
};
use futures::task::Context;
use futures::{ready, Poll};
use futures::{ready, task::Poll};
use mio::net::UdpSocket;
use std::net::{SocketAddr, SocketAddrV4, SocketAddrV6, ToSocketAddrs};
use std::ops::Deref;
use std::pin::Pin;
use tokio_net::util::PollEvented;
use tokio::io::PollEvented;

/// An asynchronous [`AsyncDatagramSocket`] wrapper around [`std::net::UdpSocket`] that
/// uses [Tokio][] for the event loop.
Expand Down Expand Up @@ -65,7 +65,7 @@ impl TokioAsyncUdpSocket {

/// Wraps a [`mio::net::UdpSocket`] instance with a [`TokioAsyncUdpSocket`].
pub(crate) fn from_mio(udp_socket: UdpSocket) -> TokioAsyncUdpSocket {
TokioAsyncUdpSocket(PollEvented::new(udp_socket))
TokioAsyncUdpSocket(PollEvented::new(udp_socket).expect("Async UDP socket"))
}
}

Expand Down
4 changes: 1 addition & 3 deletions async-coap-tokio/tests/test.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#![feature(async_await)]

use async_coap::datagram::DatagramLocalEndpoint;
use async_coap::prelude::*;
use async_coap_tokio::TokioAsyncUdpSocket;
use futures::prelude::*;
use std::sync::Arc;
use tokio::executor::spawn;
use tokio::spawn;

#[tokio::test]
async fn test_tokio() {
Expand Down
4 changes: 2 additions & 2 deletions async-coap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ rand = "0.6"
num = "0.2"
regex = "1.1"
pin-utils = "0.1.0-alpha.4"
futures-preview = { version = "=0.3.0-alpha.18", features = ["async-await", "nightly"] }
futures-timer = "0.3"
futures = {version = "0.3", features=["default", "thread-pool"]}
futures-timer = "2.0"
async-coap-uri = { path = "../async-coap-uri", version = "0.1.0" }
8 changes: 4 additions & 4 deletions async-coap/src/datagram/allow_udp_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
//

use super::*;
use futures::task::Context;
use futures::Poll;
use futures::task::{Context, Poll};
use futures_timer::Delay;
use std::net::{SocketAddr, SocketAddrV4, SocketAddrV6, UdpSocket};
use std::ops::Deref;
use std::pin::Pin;
use std::sync::Mutex;
use std::time::Duration;
use std::time::{Instant, Duration};

/// A naive wrapper around [`std::net::UdpSocket`] that implements [`AsyncDatagramSocket`].
///
Expand Down Expand Up @@ -91,12 +90,13 @@ impl AllowStdUdpSocket {
if let Some(d) = self.2 {
let mut lock = self.1.lock().expect("Lock failed");
let opt_mut: &mut Option<Delay> = &mut lock;

if opt_mut.is_none() {
*opt_mut = Some(Delay::new(d));
delay = opt_mut.as_mut().unwrap();
} else {
delay = opt_mut.as_mut().unwrap();
delay.reset(d);
delay.reset(Instant::now() + d);
}

let _ = Pin::new(delay).poll(cx);
Expand Down
3 changes: 1 addition & 2 deletions async-coap/src/datagram/async_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@

use super::*;
use futures::prelude::*;
use futures::task::Context;
use futures::Poll;
use futures::task::{Context, Poll};
use std::pin::Pin;

/// A trait for asynchronous datagram sockets.
Expand Down
16 changes: 12 additions & 4 deletions async-coap/src/datagram/local_endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,12 +338,12 @@ impl<US: AsyncDatagramSocket> LocalEndpoint for DatagramLocalEndpoint<US> {
#[cfg(test)]
mod tests {
use super::*;
use crate::message::MessageDisplay;
use crate::message::{MessageDisplay, MessageRead};
use crate::ContentFormat;
use futures::executor::block_on;
use futures::future::select;
use futures::future::Either;
use futures_timer::TryFutureExt;
use futures_timer::Delay;
use std::time::Duration;

fn test_process_request<LE, F, R>(local_endpoint: &LE, future: F) -> R
Expand Down Expand Up @@ -517,8 +517,16 @@ mod tests {
});

let future = remote_endpoint
.send(send_desc)
.timeout(Duration::from_secs(5));
.send(send_desc);

let future = select(future, Delay::new(Duration::new(5, 0)))
.map(|f| {
if let Either::Left(x) = f {
x.0
}else{
Err(Error::ResponseTimeout)
}
});

let result = test_process_request(&local_endpoint, future);
assert!(result.is_ok(), "{:?}", result);
Expand Down
3 changes: 1 addition & 2 deletions async-coap/src/datagram/loopback_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ use super::*;
use futures::channel::mpsc::{channel, Receiver, Sender};
use futures::lock::Mutex;
use futures::prelude::*;
use futures::task::Context;
use futures::Poll;
use futures::task::{Context, Poll};
use std::fmt::{Debug, Display, Formatter};
use std::pin::Pin;

Expand Down
3 changes: 1 addition & 2 deletions async-coap/src/datagram/null_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
//

use super::*;
use futures::task::Context;
use futures::Poll;
use futures::task::{Context, Poll};
use std::fmt::{Debug, Display, Formatter};
use std::pin::Pin;

Expand Down
7 changes: 3 additions & 4 deletions async-coap/src/datagram/send_future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
use super::*;
use crate::message::BufferMessageEncoder;
use futures::prelude::*;
use futures::task::Waker;
use futures::Poll;
use futures::task::{Waker, Poll};
use futures_timer::Delay;
use std::cell::Cell;
use std::fmt::{Display, Formatter};
Expand Down Expand Up @@ -136,7 +135,7 @@ where
fn update_timeout(&mut self, d: Option<Duration>) {
if let Some(d) = d {
if let Some(delay) = self.delay.as_mut() {
delay.reset(d);
delay.reset(Instant::now() + d);
} else {
self.delay = Some(Delay::new(d));
}
Expand All @@ -148,7 +147,7 @@ where
fn poll_timeout(
&mut self,
cx: &mut futures::task::Context<'_>,
) -> Poll<Result<(), std::io::Error>> {
) -> Poll<()> {
if let Some(delay) = self.delay.as_mut() {
Pin::new(delay).poll(cx)
} else {
Expand Down
9 changes: 1 addition & 8 deletions async-coap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
//! This similarly straightforward to do with *async-coap*:
//!
//! ```
//! # #![feature(async_await)]
//! # use std::sync::Arc;
//! # use futures::{prelude::*,executor::LocalPool,task::LocalSpawnExt};
//! # use async_coap::prelude::*;
Expand Down Expand Up @@ -94,7 +93,6 @@
//! convenient. The *async-coap* way to do it is similarly convenient:
//!
//! ```
//! # #![feature(async_await)]
//! # use std::sync::Arc;
//! # use futures::{prelude::*,executor::LocalPool,task::LocalSpawnExt};
//! # use async_coap::prelude::*;
Expand Down Expand Up @@ -138,7 +136,6 @@
//! [`inspect`]: send_desc::SendDescExt::inspect
//!
//! ```
//! # #![feature(async_await)]
//! # use std::sync::Arc;
//! # use futures::{prelude::*,executor::LocalPool,task::LocalSpawnExt};
//! # use async_coap::prelude::*;
Expand Down Expand Up @@ -183,15 +180,14 @@
//! This allows us to collect all of the responses:
//!
//! ```no_run
//! # #![feature(async_await)]
//! # use std::sync::Arc;
//! # use futures::{prelude::*,executor::LocalPool,task::LocalSpawnExt};
//! # use async_coap::prelude::*;
//! # use async_coap::datagram::{DatagramLocalEndpoint, AllowStdUdpSocket, LoopbackSocket};
//! # use async_coap::null::NullLocalEndpoint;
//! # use async_coap::message::MessageDisplay;
//! # use async_coap::Error;
//! # use futures_timer::TryFutureExt;
//! # use futures::future::TryFutureExt;
//! # use std::time::Duration;
//! # let socket = AllowStdUdpSocket::bind("[::]:0").expect("UDP bind failed");
//! # let local_endpoint = Arc::new(DatagramLocalEndpoint::new(socket));
Expand Down Expand Up @@ -256,8 +252,6 @@
//! ## Full Example
//!
//! ```
//! # #![feature(async_await)]
//! #
//! use std::sync::Arc;
//! use futures::{prelude::*,executor::LocalPool,task::LocalSpawnExt};
//! use async_coap::prelude::*;
Expand Down Expand Up @@ -317,7 +311,6 @@
//!
//! [send-desc]: send_desc/index.html

#![feature(async_await)]
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(rust_2018_idioms)]
#![warn(missing_debug_implementations)]
Expand Down
2 changes: 0 additions & 2 deletions async-coap/src/local_endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ use std::sync::Arc;
/// Or, more naturally, the returned futures can be used directly in `async` blocks:
///
/// ```
/// # #![feature(async_await)]
/// # use std::sync::Arc;
/// # use futures::{prelude::*,executor::LocalPool,task::LocalSpawnExt};
/// # use async_coap::prelude::*;
Expand Down Expand Up @@ -536,7 +535,6 @@ pub trait LocalEndpointExt: LocalEndpoint {
/// future in an (effectively transparent) [`ArcGuard`] wrapper.
///
/// ```
/// # #![feature(async_await)]
/// #
/// # use std::sync::Arc;
/// # use futures::prelude::*;
Expand Down
1 change: 0 additions & 1 deletion async-coap/src/remote_endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use crate::UriBuf;
/// # Example
///
/// ```
/// # #![feature(async_await)]
/// #
/// # use std::sync::Arc;
/// # use futures::{prelude::*,executor::LocalPool,task::LocalSpawnExt};
Expand Down
2 changes: 0 additions & 2 deletions async-coap/src/send_desc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
//! Here we create a `SendDesc` instance that just sends a GET request and waits for a response:
//!
//! ```
//! # #![feature(async_await)]
//! # use std::sync::Arc;
//! # use futures::{prelude::*,executor::LocalPool,task::LocalSpawnExt};
//! # use async_coap::prelude::*;
Expand Down Expand Up @@ -60,7 +59,6 @@
//! an owned copy of the message it received ([`OwnedImmutableMessage`](crate::message::OwnedImmutableMessage)):
//!
//! ```
//! # #![feature(async_await)]
//! # use std::sync::Arc;
//! # use futures::{prelude::*,executor::LocalPool,task::LocalSpawnExt};
//! # use async_coap::prelude::*;
Expand Down