captionrs 0.1.0

Advanced subtitle converter and processor
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use crate::subripfile::SubtitleError;

/// Runs CPU-bound subtitle work on Tokio's blocking pool.
///
/// The async library APIs use this helper when parsing or processing work would
/// otherwise occupy a runtime worker thread for an extended period.
pub async fn run_blocking<T, F>(task: F) -> Result<T, SubtitleError>
where
    T: Send + 'static,
    F: FnOnce() -> Result<T, SubtitleError> + Send + 'static,
{
    tokio::task::spawn_blocking(task)
        .await
        .map_err(|error| SubtitleError::Parse(format!("Async task failed: {error}")))?
}