move image decoding to blocking task
This commit is contained in:
parent
79f0e3d978
commit
5032b9d3a2
1 changed files with 13 additions and 7 deletions
|
@ -294,13 +294,19 @@ impl Client {
|
||||||
};
|
};
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
let image = ImageReader::new(std::io::BufReader::new(std::io::Cursor::new(
|
// decoding the image can take up a good chunk of cpu time, so spawn a blocking task
|
||||||
|
let image = runtime()
|
||||||
|
.spawn_blocking(move || {
|
||||||
|
ImageReader::new(std::io::BufReader::new(std::io::Cursor::new(
|
||||||
byteresponse.bytes,
|
byteresponse.bytes,
|
||||||
)))
|
)))
|
||||||
.with_guessed_format()
|
.with_guessed_format()
|
||||||
.map_err(|e| Error::ImageDecodeError(image::ImageError::IoError(e)))?
|
.map_err(|e| Error::ImageDecodeError(image::ImageError::IoError(e)))?
|
||||||
.decode()
|
.decode()
|
||||||
.map_err(Error::ImageDecodeError)?;
|
.map_err(Error::ImageDecodeError)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.expect("could not receive image from blocking tokio task")?;
|
||||||
|
|
||||||
let width = image.width();
|
let width = image.width();
|
||||||
let height = image.height();
|
let height = image.height();
|
||||||
|
|
Loading…
Reference in a new issue