Skip to content

Commit

Permalink
chore: log
Browse files Browse the repository at this point in the history
  • Loading branch information
fzyzcjy committed May 19, 2024
1 parent b1632f2 commit e63e56b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
14 changes: 13 additions & 1 deletion frb_rust/src/handler/implementation/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::platform_types::MessagePort;
use crate::rust2dart::sender::Rust2DartSender;
use crate::rust_async::BaseAsyncRuntime;
use crate::thread_pool::BaseThreadPool;
use crate::transfer;
use crate::{console_error, transfer};
#[cfg(feature = "rust-async")]
use futures::FutureExt;
use std::future::Future;
Expand Down Expand Up @@ -55,27 +55,39 @@ impl<EL: ErrorListener + Sync, TP: BaseThreadPool, AR: BaseAsyncRuntime> Executo
let el = self.error_listener;
let el2 = self.error_listener;

console_error!("hi execute_normal 1");

let TaskInfo { port, .. } = task_info;
let port: MessagePort = port.unwrap();

console_error!("hi execute_normal 2");
self.thread_pool
.execute(transfer!(|port: crate::platform_types::MessagePort| {
console_error!("hi execute_normal 3");
#[allow(clippy::clone_on_copy)]
let port2 = port.clone();
let thread_result = PanicBacktrace::catch_unwind(AssertUnwindSafe(|| {
console_error!("hi execute_normal 4");
#[allow(clippy::clone_on_copy)]
let sender = Rust2DartSender::new(Channel::new(port2.clone()));
let task_context = TaskContext::new();

console_error!("hi execute_normal 5");
let ret = task(task_context);

console_error!("hi execute_normal 6");
ExecuteNormalOrAsyncUtils::handle_result::<Rust2DartCodec, _>(ret, sender, el2);
console_error!("hi execute_normal 7");
}));

console_error!("hi execute_normal 8");
if let Err(error) = thread_result {
console_error!("hi execute_normal 9");
handle_non_sync_panic_error::<Rust2DartCodec>(el, port, error);
console_error!("hi execute_normal 10");
}
}));
console_error!("hi execute_normal 11");
}

fn execute_sync<Rust2DartCodec, SyncTaskFn>(
Expand Down
5 changes: 5 additions & 0 deletions frb_rust/src/third_party/wasm_bindgen/worker_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use web_sys::ErrorEvent;
use web_sys::MessageEvent;
use web_sys::{Blob, Url};
use web_sys::{Event, Worker};
use crate::console_error;

#[wasm_bindgen]
pub struct WorkerPool {
Expand Down Expand Up @@ -203,8 +204,11 @@ impl WorkerPool {
/// a `post_message`. Examples are `Buffer`s, `MessagePort`s, etc...
// NOTE: It is originally named `run`, but rename to align with crate `threadpool`
pub fn execute(&self, closure: TransferClosure<JsValue>) -> Result<(), JsValue> {
console_error!("hi WorkerPool.execute 1");
let worker = self.execute_raw(closure)?;
console_error!("hi WorkerPool.execute 2");
self.reclaim_on_message(&worker);
console_error!("hi WorkerPool.execute 3");
Ok(())
}
}
Expand All @@ -225,6 +229,7 @@ impl PoolState {

impl Default for WorkerPool {
fn default() -> Self {
console_error!("hi WorkerPool.default 1");
Self::new(
get_wasm_hardware_concurrency(),
script_path().expect("fail to get script path"),
Expand Down
9 changes: 8 additions & 1 deletion frb_rust/src/thread_pool/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@ pub use crate::third_party::wasm_bindgen::worker_pool::WorkerPool as SimpleThrea
use crate::web_transfer::transfer_closure::TransferClosure;
use std::thread::LocalKey;
use wasm_bindgen::JsValue;
use crate::console_error;

pub trait BaseThreadPool {
fn execute(&self, closure: TransferClosure<JsValue>);
}

impl BaseThreadPool for &'static LocalKey<SimpleThreadPool> {
fn execute(&self, closure: TransferClosure<JsValue>) {
self.with(|inner| inner.execute(closure)).unwrap()
console_error!("hi SimpleThreadPool.execute START");
let result = self.try_with(|inner| {
console_error!("hi SimpleThreadPool.execute inside with");
inner.execute(closure)
});
console_error!("hi SimpleThreadPool.execute 2 result.is_ok={:?}", result.is_ok());
todo!()
}
}

0 comments on commit e63e56b

Please sign in to comment.