Using inspiration from the actor model, we can safely share a mutable reference to a thread-unsafe instance of deno_code::JsRuntime between our web servers' asynchronous handler functions running as Future tasks in tokio threads.
The achieved architecture looks like the following:
graph TB
A["Main (Thread)"]
Dev["Dev Mode Features (Thread)"]
subgraph Tokio["Tokio Runtime (Thread Pool)"]
W["Web Server"]
C["Worker 1"]
D["Worker 2"]
E["Worker N"]
end
F["JS Runtime Manager (Thread + Singleton)"]
A -->|"Starts"| F
A -->|"Starts"| W
A -.->|"Starts"| Dev
W -->|"Starts"| C
W -->|"Starts"| D
W -->|"Starts"| E
C -->|"Accesses"| F
D -->|"Accesses"| F
E -->|"Accesses"| F
Dev -.->|"Accesses"| F
style Tokio fill:#803037
Using inspiration from the actor model, we can safely share a mutable reference to a thread-unsafe instance of
deno_code::JsRuntime
between our web servers' asynchronous handler functions running asFuture
tasks in tokio threads. The achieved architecture looks like the following:Closes
2
1