Przeglądaj źródła

Upgrade to tokio 0.3

Jing Yang 5 lat temu
rodzic
commit
2a69e5f5d2
3 zmienionych plików z 5 dodań i 6 usunięć
  1. 1 1
      Cargo.toml
  2. 3 4
      src/lib.rs
  3. 1 1
      src/utils.rs

+ 1 - 1
Cargo.toml

@@ -16,7 +16,7 @@ parking_lot = "0.11.0"
 rand = "0.7.3"
 serde = "1.0.116"
 serde_derive = "1.0.116"
-tokio = { version = "0.2.22", features = ["rt-threaded", "sync", "time"] }
+tokio = { version = "0.3", features = ["rt-multi-thread", "time", "parking_lot"] }
 
 [dev-dependencies]
 anyhow = "1.0"

+ 3 - 4
src/lib.rs

@@ -167,11 +167,10 @@ impl Raft {
         };
         election.reset_election_timer();
 
-        let thread_pool = tokio::runtime::Builder::new()
-            .threaded_scheduler()
+        let thread_pool = tokio::runtime::Builder::new_multi_thread()
             .enable_time()
             .thread_name(format!("raft-instance-{}", me))
-            .core_threads(peer_size)
+            .worker_threads(peer_size)
             .max_threads(peer_size * 2)
             .build()
             .expect("Creating thread pool should not fail");
@@ -702,7 +701,7 @@ impl Raft {
             // Do nothing, not our term anymore.
             Ok(None) => {}
             Err(_) => {
-                tokio::time::delay_for(Duration::from_millis(
+                tokio::time::sleep(Duration::from_millis(
                     HEARTBEAT_INTERVAL_MILLIS,
                 ))
                 .await;

+ 1 - 1
src/utils.rs

@@ -12,7 +12,7 @@ where
 {
     for i in 0..max_retry {
         if i != 0 {
-            tokio::time::delay_for(Duration::from_millis((1 << i) * 10)).await;
+            tokio::time::sleep(Duration::from_millis((1 << i) * 10)).await;
         }
         // Not timed-out.
         if let Ok(reply) = tokio::time::timeout(deadline, task_gen(i)).await {