Closed
Description
// main.js
const worker = new Worker('./worker.js', { type: 'module' });
worker.onmessage = ({ data }) => console.log(data);
// worker.js
self.postMessage('message');
self.close();
$ RUST_BACKTRACE=1 deno run main.js
thread 'deno-worker-0' panicked at 'Failed to post message to host: TrySendError { kind: Disconnected }', cli/ops/worker_host.rs:142:7
stack backtrace:
message
0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
1: core::fmt::write
2: std::io::Write::write_fmt
3: std::panicking::default_hook::{{closure}}
4: std::panicking::default_hook
5: std::panicking::rust_panic_with_hook
6: rust_begin_unwind
7: core::panicking::panic_fmt
8: core::result::unwrap_failed
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
thread 'main' panicked at 'Worker thread panicked: Any', cli/ops/worker_host.rs:329:11
stack backtrace:
0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
1: core::fmt::write
2: std::io::Write::write_fmt
3: std::panicking::default_hook::{{closure}}
4: std::panicking::default_hook
5: std::panicking::rust_panic_with_hook
6: rust_begin_unwind
7: core::panicking::panic_fmt
8: core::result::unwrap_failed
9: <std::future::GenFuture<T> as core::future::future::Future>::poll
10: futures_util::future::future::chain::Chain<Fut1,Fut2,Data>::poll
11: <futures_util::future::future::map::Map<Fut,F> as core::future::future::Future>::poll
12: <futures_util::future::future::map::Map<Fut,F> as core::future::future::Future>::poll
13: <&mut S as futures_core::stream::Stream>::poll_next
14: futures_util::stream::stream::StreamExt::poll_next_unpin
15: <deno_core::isolate::CoreIsolate as core::future::future::Future>::poll
16: <deno_core::es_isolate::EsIsolate as core::future::future::Future>::poll
17: <std::future::GenFuture<T> as core::future::future::Future>::poll
18: std::thread::local::LocalKey<T>::with
19: tokio::macros::scoped_tls::ScopedKey<T>::set
20: tokio::runtime::basic_scheduler::BasicScheduler<P>::block_on
21: tokio::runtime::context::enter
22: deno::tokio_util::run_basic
23: deno::main
24: std::rt::lang_start::{{closure}}
25: std::panicking::try::do_call
26: __rust_maybe_catch_panic
27: std::rt::lang_start_internal
28: main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
This works in the browser. Postponing the close until the next tick makes it work in Deno.
self.postMessage('message');
setTimeout(() => self.close(), 0);
Activity