Skip to content
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
26 changes: 23 additions & 3 deletions core/src/services/persy/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ use std::str;

use async_trait::async_trait;
use persy;
use tokio::task;

use crate::raw::adapters::kv;
use crate::raw::*;
use crate::Builder;
use crate::Error;
use crate::ErrorKind;
Expand Down Expand Up @@ -175,7 +177,12 @@ 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()))
Comment thread
Xuanwo marked this conversation as resolved.
.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 @@ -192,7 +199,14 @@ impl kv::Adapter for Adapter {
}

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

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 @@ -208,7 +222,13 @@ impl kv::Adapter for Adapter {
}

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

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