mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-13 18:27:21 +00:00
Kept the runtime API responsive during blocking work (#1043)
This commit is contained in:
1 parent
4616d1a4b2
commit
fb756dd767
11 files changed
+389
-77
No files matched your search
@@ -77,6 +77,26 @@ fn release_clipboard<B>(clipboard: &mut Option<B>) -> bool {
|
||||
|
||||
/// Sets the clipboard text to the provided encrypted text.
|
||||
pub async fn set_clipboard(_token: APIToken, encrypted_text: String) -> Json<SetClipboardResponse> {
|
||||
//
|
||||
// The clipboard backend of the operating system may take a moment to answer, a failed write is
|
||||
// retried with a fresh backend, and the lock waits for a write still running. None of this
|
||||
// belongs on a runtime worker, because all calls of the app share one HTTP/2 connection.
|
||||
//
|
||||
match tokio::task::spawn_blocking(move || set_clipboard_sync(encrypted_text)).await {
|
||||
Ok(response) => response,
|
||||
Err(error) => {
|
||||
let issue = format!("The clipboard worker failed: {error}");
|
||||
error!(Source = "Clipboard"; "{issue}");
|
||||
Json(SetClipboardResponse {
|
||||
success: false,
|
||||
issue,
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Performs the blocking part of [`set_clipboard`].
|
||||
fn set_clipboard_sync(encrypted_text: String) -> Json<SetClipboardResponse> {
|
||||
let encrypted_text = EncryptedText::new(encrypted_text);
|
||||
|
||||
// Decrypt this text first:
|
||||
|
||||
Reference in new issue
Block a user