Skip to content

Commit

Permalink
Use tokio-compat to drive CKB nodebridge
Browse files Browse the repository at this point in the history
  • Loading branch information
de1acr0ix committed Sep 12, 2020
1 parent 59e83fb commit 274448a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
18 changes: 18 additions & 0 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rust/nodebridge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
structopt = "0.3"
tokio = { version = "0.2", features = ["full"] }
tokio-compat = "0.1"
8 changes: 3 additions & 5 deletions rust/nodebridge/src/ckb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use rdkafka::producer::{FutureProducer, FutureRecord};
use rdkafka::topic_partition_list::Offset;
use rdkafka::util::Timeout;
use rdkafka::{ClientConfig, TopicPartitionList};
use tokio::runtime::Runtime;
use tokio::spawn;
use tokio::sync::mpsc::{Receiver, Sender};
use tokio::time::delay_for;
Expand Down Expand Up @@ -286,17 +285,16 @@ fn handle_messages(
}

pub fn run(
rpc_addr: &str,
rpc_addr: String,
rpc_interval: u64,
kafka_brokers: String,
job_topic: String,
solved_share_topic: String,
db_url: String,
) {
let mut runtime = Runtime::new().expect("Fail to create main runtime");
runtime.block_on(async {
tokio_compat::run_std(async move {
info!("Connecting to CKB node {}", rpc_addr);
let result = http::connect::<Client>(rpc_addr).compat().await;
let result = http::connect::<Client>(&rpc_addr).compat().await;
let rpc_client = result.expect("Failed to connect to CKB node");
let (mut tx, rx) = tokio::sync::mpsc::channel::<Message>(256);
handle_messages(
Expand Down
2 changes: 1 addition & 1 deletion rust/nodebridge/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn main() {
solved_share_topic,
db_url,
} => ckb::run(
&rpc_addr,
rpc_addr,
rpc_interval,
kafka_brokers,
job_topic,
Expand Down

0 comments on commit 274448a

Please sign in to comment.