spawn_blocking on pretty

This commit is contained in:
Dmitry Belyaev 2022-09-12 16:38:23 +03:00
parent ed87fd17ea
commit c29a247284
Signed by: b4tman
GPG Key ID: 41A00BF15EA7E5F3

View File

@ -6,7 +6,7 @@ extern crate tokio;
use async_zip::read::fs::ZipFileReader; use async_zip::read::fs::ZipFileReader;
use std::path::PathBuf; use std::path::PathBuf;
use std::str::FromStr; use std::str::FromStr;
use tokio::fs; use tokio::{fs, task};
use tokio::io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader}; use tokio::io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader};
const BASE_FILENAME: &str = "baza_utf8.zip"; const BASE_FILENAME: &str = "baza_utf8.zip";
@ -234,7 +234,9 @@ async fn process_file(
// save json to file // save json to file
let new_data = parse_file(entry_reader).await?; let new_data = parse_file(entry_reader).await?;
let data_str = new_data.pretty(2); let data_str = task::spawn_blocking(move || {
new_data.pretty(2)
}).await?;
let mut outfile = fs::File::create(outfilename).await?; let mut outfile = fs::File::create(outfilename).await?;
outfile.write_all(data_str.as_bytes()).await?; outfile.write_all(data_str.as_bytes()).await?;