mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-13 01:51:23 +00:00
feat(swarm): Add wasm-bindgen
executor (#3115)
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user