Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebDAV: add blocking() to operation which may block #141

Closed
simonsan opened this issue Jan 29, 2024 · 1 comment
Closed

WebDAV: add blocking() to operation which may block #141

simonsan opened this issue Jan 29, 2024 · 1 comment
Labels
A-vfs Area: Related to the Virtual Filesystem C-enhancement Category: New feature or request

Comments

@simonsan
Copy link
Contributor

Code taken from #106 (webdavfs.rs):

#[derive(Clone, Copy)]
enum RuntimeType {
    Basic,
    ThreadPool,
}

impl RuntimeType {
    fn get() -> Self {
        static RUNTIME_TYPE: OnceLock<RuntimeType> = OnceLock::new();
        *RUNTIME_TYPE.get_or_init(|| {
            let dbg = format!("{:?}", tokio::runtime::Handle::current());
            if dbg.contains("ThreadPool") {
                Self::ThreadPool
            } else {
                Self::Basic
            }
        })
    }
}

// Run some code via block_in_place() or spawn_blocking().
async fn blocking<F, R>(func: F) -> R
where
    F: FnOnce() -> R + Send + 'static,
    R: Send + 'static,
{
    match RuntimeType::get() {
        RuntimeType::Basic => tokio::task::spawn_blocking(func).await.unwrap(),
        RuntimeType::ThreadPool => tokio::task::block_in_place(func),
    }
}
@github-actions github-actions bot added the S-triage Status: Waiting for a maintainer to triage this issue/PR label Jan 29, 2024
@simonsan simonsan added C-enhancement Category: New feature or request A-vfs Area: Related to the Virtual Filesystem and removed S-triage Status: Waiting for a maintainer to triage this issue/PR labels Jan 31, 2024
@aawsome
Copy link
Member

aawsome commented Dec 2, 2024

don't know why we forgot about this, but in fact this was the key to our webdav problem...
Is now solved using spawn_blocking...

@aawsome aawsome closed this as completed Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-vfs Area: Related to the Virtual Filesystem C-enhancement Category: New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants