diff --git a/src/subsonic.rs b/src/subsonic.rs index 988e18d..3f51337 100644 --- a/src/subsonic.rs +++ b/src/subsonic.rs @@ -294,13 +294,19 @@ impl Client { }; return error; } - let image = ImageReader::new(std::io::BufReader::new(std::io::Cursor::new( - byteresponse.bytes, - ))) - .with_guessed_format() - .map_err(|e| Error::ImageDecodeError(image::ImageError::IoError(e)))? - .decode() - .map_err(Error::ImageDecodeError)?; + // 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, + ))) + .with_guessed_format() + .map_err(|e| Error::ImageDecodeError(image::ImageError::IoError(e)))? + .decode() + .map_err(Error::ImageDecodeError) + }) + .await + .expect("could not receive image from blocking tokio task")?; let width = image.width(); let height = image.height();