Limit tokio threads
This commit is contained in:
parent
b3d347e2b6
commit
6a7f8a4d1a
1 changed files with 5 additions and 3 deletions
|
|
@ -2,6 +2,7 @@ use std::{
|
||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
fmt::Display,
|
fmt::Display,
|
||||||
fs::{File, OpenOptions},
|
fs::{File, OpenOptions},
|
||||||
|
future::Future,
|
||||||
io::{Read, Seek, Write},
|
io::{Read, Seek, Write},
|
||||||
net::SocketAddr,
|
net::SocketAddr,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
|
|
@ -13,7 +14,7 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use futures::{stream::FuturesUnordered, StreamExt};
|
use futures::{stream::FuturesUnordered, FutureExt, StreamExt};
|
||||||
use log::{debug, error, info, trace, warn};
|
use log::{debug, error, info, trace, warn};
|
||||||
use parking_lot::{Mutex, RwLock};
|
use parking_lot::{Mutex, RwLock};
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
|
|
@ -243,7 +244,7 @@ fn spawn<N: Display + 'static + Send>(
|
||||||
fn spawn_blocking<T: Send + Sync + 'static, N: Display + 'static + Send>(
|
fn spawn_blocking<T: Send + Sync + 'static, N: Display + 'static + Send>(
|
||||||
name: N,
|
name: N,
|
||||||
f: impl FnOnce() -> anyhow::Result<T> + Send + 'static,
|
f: impl FnOnce() -> anyhow::Result<T> + Send + 'static,
|
||||||
) -> JoinHandle<anyhow::Result<T>> {
|
) -> impl Future<Output = anyhow::Result<T>> {
|
||||||
debug!("starting blocking task \"{}\"", name);
|
debug!("starting blocking task \"{}\"", name);
|
||||||
tokio::task::spawn_blocking(move || match f() {
|
tokio::task::spawn_blocking(move || match f() {
|
||||||
Ok(v) => {
|
Ok(v) => {
|
||||||
|
|
@ -255,6 +256,7 @@ fn spawn_blocking<T: Send + Sync + 'static, N: Display + 'static + Send>(
|
||||||
Err(e)
|
Err(e)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.map(|j| j.unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_lengths(torrent: &TorrentMetaV1Owned) -> anyhow::Result<Lengths> {
|
fn make_lengths(torrent: &TorrentMetaV1Owned) -> anyhow::Result<Lengths> {
|
||||||
|
|
@ -474,7 +476,7 @@ impl TorrentManager {
|
||||||
),
|
),
|
||||||
move || clone.read_chunk_blocking(peer_handle, chunk_info),
|
move || clone.read_chunk_blocking(peer_handle, chunk_info),
|
||||||
)
|
)
|
||||||
.await??;
|
.await?;
|
||||||
let tx = this
|
let tx = this
|
||||||
.inner
|
.inner
|
||||||
.locked
|
.locked
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue