-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
49 changed files
with
814 additions
and
6,554 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[build] | ||
rustflags = ["--cfg=web_sys_unstable_apis"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,4 +86,7 @@ test_video.mp4 | |
|
||
# old cli directories | ||
/tooling/cli.js | ||
/tooling/cli.rs | ||
/tooling/cli.rs | ||
|
||
# dist | ||
manager-ui/dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,14 @@ | |
resolver = "2" | ||
members = [ | ||
"manager-app", | ||
"manager-fut", | ||
"manager-wasm", | ||
"soundcore-lib", | ||
"test_data" | ||
"test_data", | ||
] | ||
|
||
[workspace.package] | ||
authors = ["Grigoris Mallios <[email protected]>"] | ||
license = "GPL-3.0-or-later" | ||
edition = "2021" | ||
|
||
|
@@ -20,9 +22,18 @@ env_logger = { version = "0.11" } | |
thiserror = { version = "1.0.40" } | ||
tokio = { version = "1" } | ||
serde = { version = "1" } | ||
serde_json = { version = "1.0" } | ||
async-trait = { version = "0.1" } | ||
futures = { version = "0.3" } | ||
wasm-bindgen-futures = { version = "0.4" } | ||
js-sys = { version = "0.3" } | ||
web-sys = { version = "0.3" } | ||
console_error_panic_hook = { version = "0.1.7" } | ||
serde-wasm-bindgen = { version = "0.6" } | ||
uuid = { version = "1.6.1" } | ||
soundcore-lib = { path = "./soundcore-lib", default-features = false } | ||
manager-fut = { path = "./manager-fut" } | ||
|
||
[profile.release] | ||
lto = true | ||
opt-level = "s" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[package] | ||
name = "manager-fut" | ||
version = "0.1.0" | ||
license.workspace = true | ||
edition.workspace = true | ||
|
||
[dependencies] | ||
futures = { workspace = true } | ||
|
||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies] | ||
tokio = { workspace = true, features = ["sync", "time", "rt", "rt-multi-thread"] } | ||
|
||
[target.'cfg(target_arch = "wasm32")'.dependencies] | ||
tokio = { workspace = true, features = ["sync", "rt", "macros"] } | ||
js-sys = { workspace = true } | ||
web-sys = { workspace = true, features = ["Window"] } | ||
wasm-bindgen-futures = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use std::time::Duration; | ||
|
||
use futures::Future; | ||
|
||
pub trait ManagerFuture { | ||
type JoinHandle: ManagerJoinHandle; | ||
|
||
fn spawn<F, O>(f: F) -> Self::JoinHandle | ||
where | ||
F: Future<Output = O> + Send + 'static, | ||
O: Send + 'static; | ||
|
||
fn spawn_local(fut: impl Future + 'static) -> Self::JoinHandle; | ||
async fn sleep(dur: Duration); | ||
async fn timeout<F, T>(dur: Duration, fut: F) -> Result<T, ()> | ||
where | ||
F: Future<Output = T>; | ||
} | ||
|
||
pub trait ManagerJoinHandle { | ||
fn abort(&self); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
mod future; | ||
|
||
pub use future::*; | ||
|
||
#[cfg(target_arch = "wasm32")] | ||
mod wasm; | ||
|
||
#[cfg(target_arch = "wasm32")] | ||
pub use wasm::*; | ||
|
||
#[cfg(not(target_arch = "wasm32"))] | ||
mod tokio; | ||
|
||
#[cfg(not(target_arch = "wasm32"))] | ||
pub use tokio::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use std::future::Future; | ||
use std::time::Duration; | ||
|
||
use tokio::task::JoinHandle; | ||
|
||
use crate::{ManagerFuture, ManagerJoinHandle}; | ||
|
||
pub struct TokioFuture; | ||
|
||
impl ManagerFuture for TokioFuture { | ||
type JoinHandle = TokioJoinHandle; | ||
|
||
fn spawn<F, O>(f: F) -> Self::JoinHandle | ||
where | ||
F: Future<Output = O> + Send + 'static, | ||
O: Send + 'static, | ||
{ | ||
TokioJoinHandle { | ||
handle: tokio::task::spawn(async move { | ||
f.await; | ||
}), | ||
} | ||
} | ||
|
||
fn spawn_local(f: impl Future + 'static) -> Self::JoinHandle { | ||
TokioJoinHandle { | ||
handle: tokio::task::spawn_local(async move { | ||
f.await; | ||
}), | ||
} | ||
} | ||
|
||
async fn sleep(dur: Duration) { | ||
tokio::time::sleep(dur).await; | ||
} | ||
|
||
async fn timeout<F, T>(dur: Duration, fut: F) -> Result<T, ()> | ||
where | ||
F: Future<Output = T>, | ||
{ | ||
tokio::time::timeout(dur, fut) | ||
Check failure on line 41 in manager-fut/src/tokio.rs
|
||
} | ||
} | ||
|
||
pub struct TokioJoinHandle { | ||
handle: JoinHandle<()>, | ||
} | ||
|
||
impl ManagerJoinHandle for TokioJoinHandle { | ||
fn abort(&self) { | ||
self.handle.abort(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
use std::{future::Future, rc::Rc, time::Duration}; | ||
use futures::pin_mut; | ||
use js_sys::Promise; | ||
use tokio::{select, sync::Notify}; | ||
use wasm_bindgen_futures::JsFuture; | ||
use web_sys::window; | ||
|
||
use crate::{ManagerFuture, ManagerJoinHandle}; | ||
|
||
pub struct WasmFuture; | ||
|
||
impl ManagerFuture for WasmFuture { | ||
type JoinHandle = WasmJoinHandle; | ||
|
||
fn spawn<F, O>(f: F) -> Self::JoinHandle | ||
where | ||
F: Future<Output = O> + Send + 'static, | ||
O: Send + 'static, | ||
{ | ||
Self::spawn_local(f) | ||
} | ||
|
||
fn spawn_local(fut: impl Future + 'static) -> Self::JoinHandle { | ||
let handle = WasmJoinHandle { | ||
quit: Rc::new(Default::default()), | ||
}; | ||
|
||
let quit = handle.quit.clone(); | ||
|
||
wasm_bindgen_futures::spawn_local(async move { | ||
select! { | ||
_ = fut => (), | ||
_ = quit.notified() => (), | ||
} | ||
}); | ||
handle | ||
} | ||
|
||
async fn sleep(dur: Duration) { | ||
JsFuture::from(Promise::new(&mut move |resolve, _reject| { | ||
window() | ||
.unwrap() | ||
.set_timeout_with_callback_and_timeout_and_arguments_0( | ||
&resolve, | ||
dur.as_millis() as i32, | ||
) | ||
.unwrap(); | ||
})) | ||
.await | ||
.unwrap(); | ||
} | ||
|
||
async fn timeout<F, T>(dur: Duration, fut: F) -> Result<T, ()> | ||
where | ||
F: Future<Output = T>, | ||
{ | ||
let sleep_future = JsFuture::from(Promise::new(&mut move |resolve, _reject| { | ||
window() | ||
.unwrap() | ||
.set_timeout_with_callback_and_timeout_and_arguments_0( | ||
&resolve, | ||
dur.as_millis() as i32, | ||
) | ||
.unwrap(); | ||
})); | ||
|
||
pin_mut!(fut); | ||
pin_mut!(sleep_future); | ||
|
||
select! { | ||
result = fut => Ok(result), | ||
_ = sleep_future => Err(()), | ||
} | ||
} | ||
} | ||
|
||
pub struct WasmJoinHandle { | ||
quit: Rc<Notify>, | ||
} | ||
|
||
impl ManagerJoinHandle for WasmJoinHandle { | ||
fn abort(&self) { | ||
self.quit.notify_one(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.