mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 08:27:55 +00:00
Merge some things from ashley-compile-to-wasm (#687)
* Make availability-store compile for WASM * Use --manifest-path instead * Make validation work on wasm! * Switch to Spawn trait * Migrate validation to std futures * Migrate network to std futures * Final changes to validation * Tidy up network * Tidy up validation * Switch branch * Migrate service * Get polkadot to compile via wasm! * Add browser-demo * Add initial browser file * Add browser-demo * Tidy * Temp switch back to substrate/master * tidy * Fix wasm build * Re-add release flag * Add the /ws bootnode to the chain specs * Copy changes from master * Switch branch * Switch libp2p and add wasm-timer * Switch back libp2p and add rand * Fix bootnodes PeerIds * use browser indexdb * Reduce changeset
This commit is contained in:
Generated
+73
-2
@@ -1319,11 +1319,26 @@ dependencies = [
|
||||
"num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-executor-preview"
|
||||
version = "0.3.0-alpha.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures-util-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-io"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "futures-io-preview"
|
||||
version = "0.3.0-alpha.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "futures-macro"
|
||||
version = "0.3.1"
|
||||
@@ -1335,6 +1350,19 @@ dependencies = [
|
||||
"syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-preview"
|
||||
version = "0.3.0-alpha.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"futures-channel-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures-executor-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures-io-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures-sink-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures-util-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-sink"
|
||||
version = "0.3.1"
|
||||
@@ -1400,7 +1428,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"futures-channel-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures-io-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures-sink-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
@@ -1454,6 +1484,7 @@ dependencies = [
|
||||
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wasm-bindgen 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2034,6 +2065,21 @@ dependencies = [
|
||||
"rocksdb 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "kvdb-web"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"futures-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"js-sys 0.3.32 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"kvdb 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"kvdb-memorydb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"send_wrapper 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wasm-bindgen 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"web-sys 0.3.32 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
@@ -3550,17 +3596,19 @@ dependencies = [
|
||||
"futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"js-sys 0.3.32 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"kvdb-memorydb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"kvdb-web 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libp2p 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"polkadot-service 0.7.9",
|
||||
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sc-cli 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
|
||||
"sc-network 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
|
||||
"sc-service 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
|
||||
"structopt 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wasm-bindgen 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wasm-bindgen-futures 0.3.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wasm-bindgen-futures 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4121,6 +4169,7 @@ dependencies = [
|
||||
"libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wasm-bindgen 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
@@ -5028,6 +5077,11 @@ name = "send_wrapper"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "send_wrapper"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.102"
|
||||
@@ -6525,6 +6579,17 @@ dependencies = [
|
||||
"web-sys 0.3.32 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-futures"
|
||||
version = "0.4.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"js-sys 0.3.32 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wasm-bindgen 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"web-sys 0.3.32 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.55"
|
||||
@@ -7051,8 +7116,11 @@ dependencies = [
|
||||
"checksum futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)" = "b35b6263fb1ef523c3056565fa67b1d16f0a8604ff12b11b08c25f28a734c60a"
|
||||
"checksum futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "ab90cde24b3319636588d0c35fe03b1333857621051837ed769faefb4c2162e4"
|
||||
"checksum futures-executor 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1e274736563f686a837a0568b478bdabfeaec2dca794b5649b04e2fe1627c231"
|
||||
"checksum futures-executor-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)" = "75236e88bd9fe88e5e8bfcd175b665d0528fe03ca4c5207fabc028c8f9d93e98"
|
||||
"checksum futures-io 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e676577d229e70952ab25f3945795ba5b16d63ca794ca9d2c860e5595d20b5ff"
|
||||
"checksum futures-io-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)" = "f4914ae450db1921a56c91bde97a27846287d062087d4a652efc09bb3a01ebda"
|
||||
"checksum futures-macro 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "52e7c56c15537adb4f76d0b7a76ad131cb4d2f4f32d3b0bcabcbe1c7c5e87764"
|
||||
"checksum futures-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)" = "3b1dce2a0267ada5c6ff75a8ba864b4e679a9e2aa44262af7a3b5516d530d76e"
|
||||
"checksum futures-sink 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "171be33efae63c2d59e6dbba34186fe0d6394fb378069a76dfd80fdcffd43c16"
|
||||
"checksum futures-sink-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)" = "86f148ef6b69f75bb610d4f9a2336d4fc88c4b5b67129d1a340dd0fd362efeec"
|
||||
"checksum futures-task 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0bae52d6b29cf440e298856fec3965ee6fa71b06aa7495178615953fd669e5f9"
|
||||
@@ -7122,6 +7190,7 @@ dependencies = [
|
||||
"checksum kvdb 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c1b2f251f01a7224426abdb2563707d856f7de995d821744fd8fa8e2874f69e3"
|
||||
"checksum kvdb-memorydb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "296c12309ed36cb74d59206406adbf1971c3baa56d5410efdb508d8f1c60a351"
|
||||
"checksum kvdb-rocksdb 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d3f82177237c1ae67d6ab208a6f790cab569a1d81c1ba02348e0736a99510be3"
|
||||
"checksum kvdb-web 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a5dddd64e88162576fdfbffc5409be89e10f95d367203321c30f8466a7774258"
|
||||
"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
"checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f"
|
||||
"checksum libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)" = "1a31a0627fdf1f6a39ec0dd577e101440b7db22672c0901fe00a9a6fbb5c24e8"
|
||||
@@ -7340,6 +7409,7 @@ dependencies = [
|
||||
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
|
||||
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
|
||||
"checksum send_wrapper 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a0eddf2e8f50ced781f288c19f18621fa72a3779e3cb58dbf23b07469b0abeb4"
|
||||
"checksum send_wrapper 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "686ef91cf020ad8d4aca9a7047641fd6add626b7b89e14546c2b6a76781cf822"
|
||||
"checksum serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4b39bd9b0b087684013a792c59e3e07a46a01d2322518d8a1104641a0b1be0"
|
||||
"checksum serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)" = "ca13fc1a832f793322228923fbb3aba9f3f44444898f835d31ad1b74fa0a2bf8"
|
||||
"checksum serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)" = "2f72eb2a68a7dc3f9a691bfda9305a1c017a6215e5a4545c258500d2099a37c2"
|
||||
@@ -7488,6 +7558,7 @@ dependencies = [
|
||||
"checksum wasm-bindgen 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)" = "29ae32af33bacd663a9a28241abecf01f2be64e6a185c6139b04f18b6385c5f2"
|
||||
"checksum wasm-bindgen-backend 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)" = "1845584bd3593442dc0de6e6d9f84454a59a057722f36f005e44665d6ab19d85"
|
||||
"checksum wasm-bindgen-futures 0.3.27 (registry+https://github.com/rust-lang/crates.io-index)" = "83420b37346c311b9ed822af41ec2e82839bfe99867ec6c54e2da43b7538771c"
|
||||
"checksum wasm-bindgen-futures 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "1458706aa1b8fe6898d19433c9f110d93a05d1f22ae6adf55810409a94df34b4"
|
||||
"checksum wasm-bindgen-macro 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)" = "87fcc747e6b73c93d22c947a6334644d22cfec5abd8b66238484dc2b0aeb9fe4"
|
||||
"checksum wasm-bindgen-macro-support 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)" = "3dc4b3f2c4078c8c4a5f363b92fcf62604c5913cbd16c6ff5aaf0f74ec03f570"
|
||||
"checksum wasm-bindgen-shared 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)" = "ca0b78d6d3be8589b95d1d49cdc0794728ca734adf36d7c9f07e6459508bb53d"
|
||||
|
||||
+13
-7
@@ -15,18 +15,22 @@ futures = { version = "0.3.1", features = ["compat"] }
|
||||
futures01 = { package = "futures", version = "0.1.29" }
|
||||
structopt = "0.3.4"
|
||||
cli = { package = "sc-cli", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
service = { package = "polkadot-service", path = "../service" }
|
||||
service = { package = "polkadot-service", path = "../service", default-features = false }
|
||||
|
||||
libp2p = { version = "0.13.0", default-features = false, optional = true }
|
||||
wasm-bindgen = { version = "0.2.45", optional = true }
|
||||
wasm-bindgen-futures = { version = "0.3.22", optional = true }
|
||||
libp2p = { version = "0.13.1", default-features = false, optional = true }
|
||||
wasm-bindgen = { version = "0.2.55", optional = true }
|
||||
wasm-bindgen-futures = { version = "0.4.5", optional = true }
|
||||
console_log = { version = "0.1.2", optional = true }
|
||||
console_error_panic_hook = { version = "0.1.1", optional = true }
|
||||
js-sys = { version = "0.3.22", optional = true }
|
||||
kvdb-memorydb = { version = "0.1.1", optional = true }
|
||||
kvdb-web = { version = "0.1.1", optional = true }
|
||||
substrate-service = { package = "sc-service", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", optional = true, default-features = false }
|
||||
substrate-network = { package = "sc-network", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", optional = true }
|
||||
|
||||
# Imported just for the `wasm-bindgen` feature
|
||||
rand = { version = "0.7", features = ["wasm-bindgen"], optional = true }
|
||||
rand6 = { package = "rand", version = "0.6.5", features = ["wasm-bindgen"], optional = true }
|
||||
|
||||
[features]
|
||||
default = [ "wasmtime", "rocksdb" ]
|
||||
wasmtime = [ "cli/wasmtime" ]
|
||||
@@ -38,7 +42,9 @@ browser = [
|
||||
"wasm-bindgen-futures",
|
||||
"console_log",
|
||||
"js-sys",
|
||||
"kvdb-memorydb",
|
||||
"kvdb-web",
|
||||
"substrate-service",
|
||||
"substrate-network"
|
||||
"substrate-network",
|
||||
"rand",
|
||||
"rand6",
|
||||
]
|
||||
|
||||
@@ -19,7 +19,7 @@ async function start() {
|
||||
|
||||
// Build our client.
|
||||
log('Starting client');
|
||||
let client = start_client(ws());
|
||||
let client = await start_client(ws());
|
||||
log('Client started');
|
||||
|
||||
client.rpcSubscribe('{"method":"chain_subscribeNewHead","params":[],"id":1,"jsonrpc":"2.0"}',
|
||||
@@ -29,7 +29,7 @@ async function start() {
|
||||
client
|
||||
.rpcSend('{"method":"system_networkState","params":[],"id":1,"jsonrpc":"2.0"}')
|
||||
.then((r) => log("Network state: " + r));
|
||||
}, 1000);
|
||||
}, 20000);
|
||||
}
|
||||
|
||||
start();
|
||||
|
||||
+33
-22
@@ -22,17 +22,19 @@ use std::sync::Arc;
|
||||
use service::{AbstractService, Roles as ServiceRoles};
|
||||
use substrate_service::{RpcSession, Configuration, config::DatabaseConfig};
|
||||
use wasm_bindgen::prelude::*;
|
||||
use futures::{compat::*, TryFutureExt as _, TryStreamExt as _, FutureExt as _};
|
||||
|
||||
/// Starts the client.
|
||||
///
|
||||
/// You must pass a libp2p transport that supports .
|
||||
#[wasm_bindgen]
|
||||
pub fn start_client(wasm_ext: wasm_ext::ffi::Transport) -> Result<Client, JsValue> {
|
||||
pub async fn start_client(wasm_ext: wasm_ext::ffi::Transport) -> Result<Client, JsValue> {
|
||||
start_inner(wasm_ext)
|
||||
.await
|
||||
.map_err(|err| JsValue::from_str(&err.to_string()))
|
||||
}
|
||||
|
||||
fn start_inner(wasm_ext: wasm_ext::ffi::Transport) -> Result<Client, Box<dyn std::error::Error>> {
|
||||
async fn start_inner(wasm_ext: wasm_ext::ffi::Transport) -> Result<Client, Box<dyn std::error::Error>> {
|
||||
console_error_panic_hook::set_once();
|
||||
console_log::init_with_level(log::Level::Info);
|
||||
|
||||
@@ -50,8 +52,10 @@ fn start_inner(wasm_ext: wasm_ext::ffi::Transport) -> Result<Client, Box<dyn std
|
||||
config.roles = ServiceRoles::LIGHT;
|
||||
config.name = "Browser node".to_string();
|
||||
config.database = {
|
||||
let db = Arc::new(kvdb_memorydb::create(10));
|
||||
DatabaseConfig::Custom(db)
|
||||
let db = kvdb_web::Database::open("polkadot".into(), 10)
|
||||
.await
|
||||
.unwrap();
|
||||
DatabaseConfig::Custom(Arc::new(db))
|
||||
};
|
||||
config.keystore_path = Some(std::path::PathBuf::from("/"));
|
||||
config
|
||||
@@ -99,8 +103,8 @@ fn start_inner(wasm_ext: wasm_ext::ffi::Transport) -> Result<Client, Box<dyn std
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Async::NotReady)
|
||||
}));
|
||||
Ok::<_, ()>(Async::NotReady)
|
||||
}).compat().map(drop));
|
||||
|
||||
Ok(Client {
|
||||
rpc_send_tx,
|
||||
@@ -116,7 +120,7 @@ pub struct Client {
|
||||
struct RpcMessage {
|
||||
rpc_json: String,
|
||||
session: RpcSession,
|
||||
send_back: oneshot::Sender<Box<dyn Future<Item = Option<String>, Error = ()>>>,
|
||||
send_back: oneshot::Sender<Box<dyn Future<Item = Option<String>, Error = ()> + Unpin>>,
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
@@ -132,9 +136,10 @@ impl Client {
|
||||
send_back: tx,
|
||||
});
|
||||
let fut = rx
|
||||
.compat()
|
||||
.map_err(|_| ())
|
||||
.and_then(|fut| fut)
|
||||
.map(|s| JsValue::from_str(&s.unwrap_or(String::new())))
|
||||
.and_then(|fut| fut.compat())
|
||||
.map_ok(|s| JsValue::from_str(&s.unwrap_or(String::new())))
|
||||
.map_err(|_| JsValue::NULL);
|
||||
wasm_bindgen_futures::future_to_promise(fut)
|
||||
}
|
||||
@@ -151,19 +156,25 @@ impl Client {
|
||||
send_back: fut_tx,
|
||||
});
|
||||
let fut_rx = fut_rx
|
||||
.compat()
|
||||
.map_err(|_| ())
|
||||
.and_then(|fut| fut);
|
||||
wasm_bindgen_futures::spawn_local(fut_rx.then(|_| Ok(())));
|
||||
wasm_bindgen_futures::spawn_local(rx.for_each(move |s| {
|
||||
match callback.call1(&callback, &JsValue::from_str(&s)) {
|
||||
Ok(_) => Ok(()),
|
||||
Err(_) => Err(()),
|
||||
}
|
||||
}).then(move |v| {
|
||||
// We need to keep `rpc_session` alive.
|
||||
debug!("RPC subscription has ended");
|
||||
drop(rpc_session);
|
||||
v
|
||||
}));
|
||||
.and_then(|fut| fut.compat())
|
||||
.map(drop);
|
||||
wasm_bindgen_futures::spawn_local(fut_rx);
|
||||
wasm_bindgen_futures::spawn_local(rx
|
||||
.compat()
|
||||
.try_for_each(move |s| {
|
||||
match callback.call1(&callback, &JsValue::from_str(&s)) {
|
||||
Ok(_) => futures::future::ready(Ok(())),
|
||||
Err(_) => futures::future::ready(Err(())),
|
||||
}
|
||||
})
|
||||
.then(move |_| {
|
||||
// We need to keep `rpc_session` alive.
|
||||
debug!("RPC subscription has ended");
|
||||
drop(rpc_session);
|
||||
futures::future::ready(())
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user