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

feat(services/redb): change blocking_x in async_x call to tokio::task::blocking_spawn #3276

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions core/src/services/redb/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ use std::sync::Arc;

use async_trait::async_trait;
use redb::ReadableTable;
use tokio::task;

use crate::raw::adapters::kv;
use crate::raw::*;
use crate::Builder;
use crate::Error;
use crate::ErrorKind;
Expand Down Expand Up @@ -132,7 +134,13 @@ impl kv::Adapter for Adapter {
}

async fn get(&self, path: &str) -> Result<Option<Vec<u8>>> {
self.blocking_get(path)
let cloned_self = self.clone();
let cloned_path = path.to_string();

task::spawn_blocking(move || cloned_self.blocking_get(cloned_path.as_str()))
.await
.map_err(new_task_join_error)
.and_then(|inner_result| inner_result)
}

fn blocking_get(&self, path: &str) -> Result<Option<Vec<u8>>> {
Expand All @@ -154,7 +162,14 @@ impl kv::Adapter for Adapter {
}

async fn set(&self, path: &str, value: &[u8]) -> Result<()> {
self.blocking_set(path, value)
let cloned_self = self.clone();
let cloned_path = path.to_string();
let cloned_value = value.to_vec();

task::spawn_blocking(move || cloned_self.blocking_set(cloned_path.as_str(), &cloned_value))
.await
.map_err(new_task_join_error)
.and_then(|inner_result| inner_result)
}

fn blocking_set(&self, path: &str, value: &[u8]) -> Result<()> {
Expand All @@ -176,7 +191,13 @@ impl kv::Adapter for Adapter {
}

async fn delete(&self, path: &str) -> Result<()> {
self.blocking_delete(path)
let cloned_self = self.clone();
let cloned_path = path.to_string();

task::spawn_blocking(move || cloned_self.blocking_delete(cloned_path.as_str()))
.await
.map_err(new_task_join_error)
.and_then(|inner_result| inner_result)
}

fn blocking_delete(&self, path: &str) -> Result<()> {
Expand Down