mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-16 11:31:22 +00:00
*: Enable libp2p to run via wasm32-unknown-unknown in the browser (#2320)
Changes needed to get libp2p to run via `wasm32-unknown-unknown` in the browser (both main thread and inside web workers). Replaces wasm-timer with futures-timer and instant. Co-authored-by: Oliver Wangler <oliver@wngr.de>
This commit is contained in:
@ -21,6 +21,7 @@
|
||||
use crate::protocol;
|
||||
use futures::future::BoxFuture;
|
||||
use futures::prelude::*;
|
||||
use futures_timer::Delay;
|
||||
use libp2p_core::{upgrade::NegotiationError, UpgradeError};
|
||||
use libp2p_swarm::{
|
||||
KeepAlive, NegotiatedSubstream, ProtocolsHandler, ProtocolsHandlerEvent,
|
||||
@ -35,7 +36,6 @@ use std::{
|
||||
time::Duration,
|
||||
};
|
||||
use void::Void;
|
||||
use wasm_timer::Delay;
|
||||
|
||||
/// The configuration for outbound pings.
|
||||
#[derive(Clone, Debug)]
|
||||
@ -349,15 +349,10 @@ impl ProtocolsHandler for Handler {
|
||||
self.outbound = Some(PingState::Idle(stream));
|
||||
break;
|
||||
}
|
||||
Poll::Ready(Ok(())) => {
|
||||
Poll::Ready(()) => {
|
||||
self.timer.reset(self.config.timeout);
|
||||
self.outbound = Some(PingState::Ping(protocol::send_ping(stream).boxed()));
|
||||
}
|
||||
Poll::Ready(Err(e)) => {
|
||||
return Poll::Ready(ProtocolsHandlerEvent::Close(Failure::Other {
|
||||
error: Box::new(e),
|
||||
}))
|
||||
}
|
||||
},
|
||||
Some(PingState::OpenStream) => {
|
||||
self.outbound = Some(PingState::OpenStream);
|
||||
|
Reference in New Issue
Block a user