Skip to content
Snippets Groups Projects
Commit 826909f8 authored by Falk Rehse's avatar Falk Rehse
Browse files

Switch back to rust spawn

While websockets are blocking.
parent 0c1ac474
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ use std::io::Error; ...@@ -3,6 +3,7 @@ use std::io::Error;
use std::net::TcpListener; use std::net::TcpListener;
use std::net::TcpStream; use std::net::TcpStream;
use std::sync::Arc; use std::sync::Arc;
use std::thread::spawn;
use tungstenite::accept; use tungstenite::accept;
use tungstenite::Message; use tungstenite::Message;
...@@ -16,7 +17,8 @@ pub async fn handle_websockets( ...@@ -16,7 +17,8 @@ pub async fn handle_websockets(
websockets_bind_address: &str, websockets_bind_address: &str,
playlist_websocket: &Mutable<Vec<Song>>, playlist_websocket: &Mutable<Vec<Song>>,
) { ) {
let server = TcpListener::bind(websockets_bind_address).expect("Failed to bind websocket port!"); let server =
TcpListener::bind(websockets_bind_address).expect("Failed to bind websocket port!");
println!( println!(
"Listening for websocket connections on {}!", "Listening for websocket connections on {}!",
...@@ -28,19 +30,18 @@ pub async fn handle_websockets( ...@@ -28,19 +30,18 @@ pub async fn handle_websockets(
let player_token_clone = Arc::clone(player_token); let player_token_clone = Arc::clone(player_token);
let client_token_clone = Arc::clone(client_token); let client_token_clone = Arc::clone(client_token);
tokio::task::spawn(async move { spawn(move || {
handle_websocket( handle_websocket(
stream, stream,
playlist_clone, playlist_clone,
player_token_clone, player_token_clone,
client_token_clone, client_token_clone,
) );
.await;
}); });
} }
} }
async fn handle_websocket( fn handle_websocket(
stream: Result<TcpStream, Error>, stream: Result<TcpStream, Error>,
playlist: Mutable<Vec<Song>>, playlist: Mutable<Vec<Song>>,
player_token: Arc<String>, player_token: Arc<String>,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment