|
1 | 1 | use crate::{ |
2 | 2 | db::datastore::locking_tx_datastore::MutTxId, |
3 | 3 | host::{ |
4 | | - module_host::{DynModule, Module, ModuleInfo, ModuleInstance}, |
| 4 | + module_host::{DynModule, Module, ModuleInfo, ModuleInstance, ModuleRuntime}, |
5 | 5 | Scheduler, |
6 | 6 | }, |
7 | 7 | module_host_context::ModuleCreationContext, |
8 | 8 | replica_context::ReplicaContext, |
9 | 9 | }; |
10 | 10 | use anyhow::anyhow; |
11 | | -use std::sync::{Arc, Once}; |
| 11 | +use std::sync::{Arc, LazyLock}; |
12 | 12 |
|
13 | 13 | use super::module_host::CallReducerParams; |
14 | 14 |
|
| 15 | +/// The V8 runtime, for modules written in e.g., JS or TypeScript. |
| 16 | +#[derive(Default)] |
15 | 17 | pub struct V8Runtime { |
16 | 18 | _priv: (), |
17 | 19 | } |
18 | 20 |
|
19 | | -impl V8Runtime { |
| 21 | +impl ModuleRuntime for V8Runtime { |
| 22 | + fn make_actor(&self, mcc: ModuleCreationContext<'_>) -> anyhow::Result<impl Module> { |
| 23 | + V8_RUNTIME_GLOBAL.make_actor(mcc) |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +static V8_RUNTIME_GLOBAL: LazyLock<V8RuntimeInner> = LazyLock::new(V8RuntimeInner::new); |
| 28 | + |
| 29 | +/// The actual V8 runtime, with initialization of V8. |
| 30 | +struct V8RuntimeInner { |
| 31 | + _priv: (), |
| 32 | +} |
| 33 | + |
| 34 | +impl V8RuntimeInner { |
20 | 35 | #[allow(clippy::new_without_default)] |
21 | | - pub fn new() -> Self { |
22 | | - static V8_INIT: Once = Once::new(); |
23 | | - V8_INIT.call_once(|| { |
24 | | - // TODO |
25 | | - }); |
| 36 | + const fn new() -> Self { |
| 37 | + // TODO: actually setup V8. |
26 | 38 |
|
27 | 39 | Self { _priv: () } |
28 | 40 | } |
29 | 41 |
|
30 | | - pub fn make_actor(&self, _: ModuleCreationContext<'_>) -> anyhow::Result<impl Module> { |
| 42 | + fn make_actor(&self, _: ModuleCreationContext<'_>) -> anyhow::Result<impl Module> { |
31 | 43 | Err::<JsModule, _>(anyhow!("v8_todo")) |
32 | 44 | } |
33 | 45 | } |
|
0 commit comments