Skip to content
This repository was archived by the owner on Dec 31, 2022. It is now read-only.

Commit a59be72

Browse files
committed
async rwlock
1 parent 4003031 commit a59be72

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/stream.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use std::env;
99
use std::fs;
1010
use std::io::Write;
1111
use std::process::{Command, Stdio};
12-
use std::sync::RwLock;
1312

1413
use actix_web::web::{self, Data, Json, ServiceConfig};
1514
use diesel::backend::Backend;
@@ -20,8 +19,8 @@ use log::{debug, trace};
2019
use rand::Rng;
2120
use serde::{Deserialize, Serialize};
2221
use tera::{Context, Tera};
22+
use tokio::sync::RwLock;
2323

24-
use crate::{do_read, do_write};
2524
use crate::error::Result;
2625
use crate::db::{ConnectionPool, PooledConnection};
2726
use crate::prochost::ProcHost;
@@ -310,9 +309,11 @@ async fn get_stream(
310309
stream: Data<RwLock<Stream>>,
311310
) -> Result<Json<StreamState>> {
312311

313-
let stream = do_read!(stream);
312+
let state = stream.read()
313+
.await
314+
.state();
314315

315-
Ok(Json(stream.state()))
316+
Ok(Json(state))
316317
}
317318

318319

@@ -324,9 +325,10 @@ async fn patch_stream(
324325
body: Json<StreamUpdate>,
325326
) -> Result<Json<StreamState>> {
326327

327-
let mut stream = do_write!(stream);
328328
let conn = pool.get()?;
329329

330+
let mut stream = stream.write()
331+
.await;
330332
stream.update(&body, &conn, &templates)
331333
.await?;
332334

0 commit comments

Comments
 (0)