Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
fix: switch swarm executor for wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
tchardin committed Feb 15, 2022
1 parent cd4c371 commit 91f9a5a
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,22 @@ use libipld::store::StoreParams;
use libipld::Cid;
use libipld::Ipld;
use libp2p::futures::StreamExt;
#[cfg(feature = "browser")]
use libp2p::swarm::SwarmBuilder;
use libp2p::swarm::{Swarm, SwarmEvent};
use libp2p::wasm_ext;
use libp2p::{
self, core, core::muxing::StreamMuxerBox, core::transport::Boxed,
core::transport::OptionalTransport, identity, mplex, noise, yamux, Multiaddr, PeerId,
Transport,
};
#[cfg(feature = "native")]
use libp2p::{dns, tcp, websocket};
use rand::prelude::*;
use std::sync::Arc;
use std::time::Duration;

#[cfg(feature = "native")]
use libp2p::{dns, tcp, websocket};
#[cfg(feature = "browser")]
use wasm_bindgen_futures;

#[cfg(feature = "native")]
use async_std::task;
Expand Down Expand Up @@ -66,8 +69,16 @@ where
Graphsync::new(GraphsyncConfig::default(), store.clone()),
);

#[cfg(feature = "native")]
let mut swarm = Swarm::new(transport, behaviour, local_peer_id);

#[cfg(feature = "browser")]
let mut swarm = SwarmBuilder::new(transport, behaviour, local_peer_id)
.executor(Box::new(|fut| {
wasm_bindgen_futures::spawn_local(fut);
}))
.build();

if let Some(maddr) = config.listening_multiaddr {
Swarm::listen_on(&mut swarm, maddr).unwrap();
}
Expand Down

0 comments on commit 91f9a5a

Please sign in to comment.