feat(swarm): Add wasm-bindgen executor (#3115)

This commit is contained in:
Hannes
2022-11-24 23:12:35 +01:00
committed by GitHub
parent 98336b7885
commit cff84f1897
4 changed files with 38 additions and 1 deletions

View File

@ -420,6 +420,29 @@ where
builder.build()
}
/// Builds a new `Swarm` with a wasm executor.
/// Background tasks will be executed by the browser on the next micro-tick.
///
/// Spawning a task is similar too:
/// ```typescript
/// function spawn(task: () => Promise<void>) {
/// task()
/// }
/// ```
#[cfg(feature = "wasm-bindgen")]
pub fn with_wasm_executor(
transport: transport::Boxed<(PeerId, StreamMuxerBox)>,
behaviour: TBehaviour,
local_peer_id: PeerId,
) -> Self {
Self::with_executor(
transport,
behaviour,
local_peer_id,
crate::executor::WasmBindgenExecutor,
)
}
/// Builds a new `Swarm` without an executor, instead using the current task.
///
/// ## ⚠️ Performance warning