Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
22
24
73 changes: 46 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ miette = { version = "7.2.0", features = ["fancy", "syntect-highlighter"] }
kill_tree = { version = "0.2.4", features = ["tokio"] }
sqids = "0.4.2"
tokio-util = "0.7.11"
shell-words = "1.1.1"

[profile.release]
strip = true
Expand Down
4 changes: 2 additions & 2 deletions bslive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ serde_json = { workspace = true }
actix-rt = { workspace = true }

# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
napi-derive = "2.16.13"
napi-derive = "3.5.10"

[dependencies.napi]
version = "2.16.17"
version = "3.10.5"
default-features = false
features = ["napi4", "serde", "serde-json"]

Expand Down
42 changes: 42 additions & 0 deletions bslive/src/async_start.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use bsnext_system::cli::from_args;
use napi::Env;
use std::env::current_dir;
use std::path::PathBuf;

pub struct AsyncStart {
pub(crate) args: Vec<String>,
pub(crate) rx: Option<tokio::sync::oneshot::Receiver<()>>,
}

impl napi::Task for AsyncStart {
type Output = i32;
type JsValue = i32;

fn compute(&mut self) -> napi::Result<Self::Output> {
let sys = actix_rt::System::new();
let args = self.args.clone();
let rx = self.rx.take().expect("must be there");
let cwd = PathBuf::from(current_dir().unwrap().to_string_lossy().to_string());
unsafe {
std::env::set_var("RUST_LIB_BACKTRACE", "0");
}
let result = sys.block_on(async move {
tokio::select! {
_ = rx => {
2
}
res = from_args(args, cwd) => {
match res {
Ok(_) => 0,
Err(_) => 1,
}
}
}
});
Ok(result)
}

fn resolve(&mut self, _: Env, output: Self::Output) -> napi::Result<Self::JsValue> {
napi::Result::Ok(output)
}
}
21 changes: 21 additions & 0 deletions bslive/src/blocking_start.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use bsnext_system::cli::from_args;
use std::env::current_dir;
use std::path::PathBuf;

/// Launch in a blocking way
#[allow(dead_code)]
#[napi]
pub fn start_blocking(args: Vec<String>) -> napi::bindgen_prelude::Result<i32> {
let sys = actix_rt::System::new();
let result = sys.block_on(async move {
let cwd = PathBuf::from(current_dir().unwrap().to_string_lossy().to_string());
unsafe {
std::env::set_var("RUST_LIB_BACKTRACE", "0");
}
match from_args(args, cwd).await {
Ok(_) => 0,
Err(_) => 1,
}
});
Ok(result)
}
56 changes: 4 additions & 52 deletions bslive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,11 @@
#[macro_use]
extern crate napi_derive;

use bsnext_system::cli::from_args;
use crate::async_start::AsyncStart;
use napi::bindgen_prelude::{AbortSignal, AsyncTask};
use napi::{Env, JsNumber};

/// Launch in a blocking way
#[allow(dead_code)]
#[napi]
fn start_blocking(args: Vec<String>) -> napi::bindgen_prelude::Result<i32> {
let sys = actix_rt::System::new();
let result = sys.block_on(async move {
match from_args(args).await {
Ok(_) => 0,
Err(_) => 1,
}
});
Ok(result)
}

pub struct AsyncStart {
args: Vec<String>,
rx: Option<tokio::sync::oneshot::Receiver<()>>,
}

impl napi::Task for AsyncStart {
type Output = i32;
type JsValue = JsNumber;

fn compute(&mut self) -> napi::Result<Self::Output> {
let sys = actix_rt::System::new();
let args = self.args.clone();
let rx = self.rx.take().expect("must be there");
let result = sys.block_on(async move {
tokio::select! {
_ = rx => {
println!("did exit from one-shot");
2
}
res = from_args(args) => {
println!("did exit from server-shot");
match res {
Ok(_) => 0,
Err(_) => 1,
}
}
}
});
Ok(result)
}

fn resolve(&mut self, env: Env, output: Self::Output) -> napi::Result<Self::JsValue> {
env.create_int32(output)
}
}
mod async_start;
mod blocking_start;

#[napi(js_name = "BsSystem")]
pub struct JsBsSystem {
Expand Down Expand Up @@ -88,7 +40,7 @@ impl JsBsSystem {
system: BsSystem::new(),
}
}
#[napi]
#[napi(ts_return_type = "Promise<number>")]
pub fn start(&mut self, args: Vec<String>, signal: AbortSignal) -> AsyncTask<AsyncStart> {
let (tx, rx) = tokio::sync::oneshot::channel::<()>();
self.system.sender = Some(tx);
Expand Down
12 changes: 10 additions & 2 deletions bsnext/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use actix_rt::System;
use std::env::args;
use std::env::{args, current_dir};
use std::path::PathBuf;
use std::process;

use bsnext_system::cli::from_args;

fn main() {
unsafe {
std::env::set_var("RUST_LIB_BACKTRACE", "0");
}
let code = System::with_tokio_rt(|| {
// build system with a multi-thread tokio runtime.
tokio::runtime::Builder::new_multi_thread()
Expand All @@ -20,7 +24,11 @@ fn main() {

async fn async_main() -> i32 {
let cli_args = args();
match from_args(cli_args).await {
let cwd = PathBuf::from(current_dir().unwrap().to_string_lossy().to_string());
unsafe {
std::env::set_var("RUST_LIB_BACKTRACE", "0");
}
match from_args(cli_args, cwd).await {
Ok(_) => 0,
Err(_) => 1,
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bsnext_core/src/server/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[test]
fn test_api_error() {
use bsnext_dto::internal::ServerError;
use bsnext_dto::server_events::ServerError;
#[derive(serde::Serialize, serde::Deserialize, Debug)]
struct Output {
error: ServerError,
Expand Down
2 changes: 1 addition & 1 deletion crates/bsnext_core/src/server/handler_listen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::server::state::ServerState;
use crate::servers_supervisor::get_servers_handler::{GetActiveServers, IncomingEvents};
use actix::{Recipient, ResponseFuture};
use actix_rt::Arbiter;
use bsnext_dto::internal::ServerError;
use bsnext_dto::server_events::ServerError;
use bsnext_input::server_config::ServerIdentity;
use std::io::ErrorKind;
use std::net::{SocketAddr, TcpListener};
Expand Down
Loading
Loading