mirror of
https://github.com/mimblewimble/grin-wallet.git
synced 2025-02-01 08:51:09 +03:00
Shutdown runtime after task is completed (#331)
* Use current thread for tokio runtime * Use single thread runtime with shutdown
This commit is contained in:
parent
4bb0398e21
commit
4774704aeb
2 changed files with 14 additions and 8 deletions
|
@ -31,7 +31,7 @@ use serde_json;
|
|||
use std::fmt::{self, Display};
|
||||
use std::net::SocketAddr;
|
||||
use std::time::Duration;
|
||||
use tokio::runtime::Runtime;
|
||||
use tokio::runtime::Builder;
|
||||
|
||||
/// Errors that can be returned by an ApiEndpoint implementation.
|
||||
#[derive(Debug)]
|
||||
|
@ -389,8 +389,12 @@ impl Client {
|
|||
|
||||
pub fn send_request(&self, req: Request<Body>) -> Result<String, Error> {
|
||||
let task = self.send_request_async(req);
|
||||
let mut rt =
|
||||
Runtime::new().context(ErrorKind::Internal("can't create Tokio runtime".to_owned()))?;
|
||||
Ok(rt.block_on(task)?)
|
||||
let mut rt = Builder::new()
|
||||
.core_threads(1)
|
||||
.build()
|
||||
.context(ErrorKind::Internal("can't create Tokio runtime".to_owned()))?;
|
||||
let res = rt.block_on(task);
|
||||
let _ = rt.shutdown_now().wait();
|
||||
res
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,10 +17,10 @@
|
|||
use crate::api::{self, LocatedTxKernel, OutputListing, OutputPrintable};
|
||||
use crate::core::core::{Transaction, TxKernel};
|
||||
use crate::libwallet::{NodeClient, NodeVersionInfo};
|
||||
use futures::{stream, Stream};
|
||||
use futures::{stream, Future, Stream};
|
||||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
use tokio::runtime::Runtime;
|
||||
use tokio::runtime::Builder;
|
||||
|
||||
use crate::client_utils::Client;
|
||||
use crate::libwallet;
|
||||
|
@ -237,8 +237,10 @@ impl NodeClient for HTTPNodeClient {
|
|||
}
|
||||
|
||||
let task = stream::futures_unordered(tasks).collect();
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
let results: Vec<OutputPrintable> = match rt.block_on(task) {
|
||||
let mut rt = Builder::new().core_threads(1).build().unwrap();
|
||||
let res = rt.block_on(task);
|
||||
let _ = rt.shutdown_now().wait();
|
||||
let results: Vec<OutputPrintable> = match res {
|
||||
Ok(resps) => {
|
||||
let mut results = vec![];
|
||||
for r in resps {
|
||||
|
|
Loading…
Reference in a new issue