Skip to content

Commit 7382eaf

Browse files
committed
json-rpc: Clarify hack for tokio 0.2 compatibility
1 parent 3a3198f commit 7382eaf

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

runtime/wasm/src/host_exports.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,5 +680,8 @@ fn test_string_to_h160_with_0x() {
680680
fn block_on<I: Send + 'static, ER: Send + 'static>(
681681
future: impl Future<Item = I, Error = ER> + Send + 'static,
682682
) -> Result<I, ER> {
683-
graph::spawn_blocking_allow_panic(future.compat()).compat().wait().unwrap()
683+
graph::spawn_blocking_allow_panic(future.compat())
684+
.compat()
685+
.wait()
686+
.unwrap()
684687
}

server/json-rpc/src/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,9 @@ where
218218
}
219219
}));
220220

221-
async fn block_on<I: Send + 'static, ER: Send + 'static>(
221+
// This is a hack required because the json-rpc crate is not updated to tokio 0.2.
222+
// We should watch the `jsonrpsee` crate and switch to that once it's ready.
223+
async fn tokio02_spawn<I: Send + 'static, ER: Send + 'static>(
222224
mut task_sink: mpsc::Sender<Box<dyn std::future::Future<Output = ()> + Send + Unpin>>,
223225
future: impl std::future::Future<Output = Result<I, ER>> + Send + Unpin + 'static,
224226
) -> Result<I, ER>
@@ -240,7 +242,7 @@ where
240242
let sender = task_sender.clone();
241243
handler.add_method("subgraph_create", move |params: Params| {
242244
let me = me.clone();
243-
Box::pin(block_on(
245+
Box::pin(tokio02_spawn(
244246
sender.clone(),
245247
params
246248
.parse()
@@ -255,7 +257,7 @@ where
255257
let sender = task_sender.clone();
256258
handler.add_method("subgraph_deploy", move |params: Params| {
257259
let me = me.clone();
258-
Box::pin(block_on(
260+
Box::pin(tokio02_spawn(
259261
sender.clone(),
260262
params
261263
.parse()
@@ -270,7 +272,7 @@ where
270272
let sender = task_sender.clone();
271273
handler.add_method("subgraph_remove", move |params: Params| {
272274
let me = me.clone();
273-
Box::pin(block_on(
275+
Box::pin(tokio02_spawn(
274276
sender.clone(),
275277
params
276278
.parse()
@@ -285,7 +287,7 @@ where
285287
let sender = task_sender.clone();
286288
handler.add_method("subgraph_reassign", move |params: Params| {
287289
let me = me.clone();
288-
Box::pin(block_on(
290+
Box::pin(tokio02_spawn(
289291
sender.clone(),
290292
params
291293
.parse()

0 commit comments

Comments
 (0)