Skip to content

Commit

Permalink
use stable async Future test
Browse files Browse the repository at this point in the history
  • Loading branch information
shenjackyuanjie committed Feb 20, 2024
1 parent 074bada commit a61f39a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
11 changes: 5 additions & 6 deletions socketio/src/asynchronous/client/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ use rust_engineio::{
asynchronous::ClientBuilder as EngineIoClientBuilder,
header::{HeaderMap, HeaderValue},
};
use std::collections::HashMap;
use url::Url;

use std::collections::HashMap;
use std::future::Future;

use crate::{error::Result, Error, Event, Payload, TransportType};

use super::{
Expand Down Expand Up @@ -170,10 +172,7 @@ impl ClientBuilder {
#[cfg(feature = "async-callbacks")]
pub fn on<T: Into<Event>, F>(mut self, event: T, callback: F) -> Self
where
F: for<'a> std::ops::FnMut(Payload, Client) -> BoxFuture<'static, ()>
+ 'static
+ Send
+ Sync,
F: FnMut(Payload, Client) -> Future<Output = ()> + 'static + Send + Sync,
{
self.on
.insert(event.into(), Callback::<DynAsyncCallback>::new(callback));
Expand Down Expand Up @@ -204,7 +203,7 @@ impl ClientBuilder {
/// ```
pub fn on_any<F>(mut self, callback: F) -> Self
where
F: for<'a> FnMut(Event, Payload, Client) -> BoxFuture<'static, ()> + 'static + Send + Sync,
F: FnMut(Event, Payload, Client) -> Future<Output = ()> + 'static + Send + Sync,
{
self.on_any = Some(Callback::<DynAsyncAnyCallback>::new(callback));
self
Expand Down
13 changes: 7 additions & 6 deletions socketio/src/asynchronous/client/callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ use std::{
fmt::Debug,
ops::{Deref, DerefMut},
};
use std::future::Future;

use crate::{Event, Payload};

use super::client::Client;

/// Internal type, provides a way to store futures and return them in a boxed manner.
pub(crate) type DynAsyncCallback =
Box<dyn for<'a> FnMut(Payload, Client) -> BoxFuture<'static, ()> + 'static + Send + Sync>;
Box<dyn FnMut(Payload, Client) -> Future<Output = ()> + 'static + Send + Sync>;

pub(crate) type DynAsyncAnyCallback = Box<
dyn for<'a> FnMut(Event, Payload, Client) -> BoxFuture<'static, ()> + 'static + Send + Sync,
dyn FnMut(Event, Payload, Client) -> Future<Output = ()> + 'static + Send + Sync,
>;

pub(crate) struct Callback<T> {
Expand All @@ -28,7 +29,7 @@ impl<T> Debug for Callback<T> {

impl Deref for Callback<DynAsyncCallback> {
type Target =
dyn for<'a> FnMut(Payload, Client) -> BoxFuture<'static, ()> + 'static + Sync + Send;
dyn FnMut(Payload, Client) -> Future<Output = ()> + 'static + Sync + Send;

fn deref(&self) -> &Self::Target {
self.inner.as_ref()
Expand All @@ -44,7 +45,7 @@ impl DerefMut for Callback<DynAsyncCallback> {
impl Callback<DynAsyncCallback> {
pub(crate) fn new<T>(callback: T) -> Self
where
T: for<'a> FnMut(Payload, Client) -> BoxFuture<'static, ()> + 'static + Sync + Send,
T: FnMut(Payload, Client) -> Future<Output = ()> + 'static + Sync + Send,
{
Callback {
inner: Box::new(callback),
Expand All @@ -54,7 +55,7 @@ impl Callback<DynAsyncCallback> {

impl Deref for Callback<DynAsyncAnyCallback> {
type Target =
dyn for<'a> FnMut(Event, Payload, Client) -> BoxFuture<'static, ()> + 'static + Sync + Send;
dyn for<'a> FnMut(Event, Payload, Client) -> Future<Output = ()> + 'static + Sync + Send;

fn deref(&self) -> &Self::Target {
self.inner.as_ref()
Expand All @@ -70,7 +71,7 @@ impl DerefMut for Callback<DynAsyncAnyCallback> {
impl Callback<DynAsyncAnyCallback> {
pub(crate) fn new<T>(callback: T) -> Self
where
T: for<'a> FnMut(Event, Payload, Client) -> BoxFuture<'static, ()> + 'static + Sync + Send,
T: FnMut(Event, Payload, Client) -> Future<Output = ()> + 'static + Sync + Send,
{
Callback {
inner: Box::new(callback),
Expand Down

0 comments on commit a61f39a

Please sign in to comment.