Skip to content

Commit 3613467

Browse files
committed
Fix build of spin-timer example
Signed-off-by: Alex Crichton <[email protected]>
1 parent bd34327 commit 3613467

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

examples/spin-timer/src/lib.rs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use std::collections::HashMap;
22

3+
use anyhow::Context;
34
use clap::Args;
45
use serde::{Deserialize, Serialize};
5-
use spin_app::MetadataKey;
6-
use spin_core::async_trait;
7-
use spin_trigger::{EitherInstance, TriggerAppEngine, TriggerExecutor};
6+
use spin_app::{AppComponent, MetadataKey};
7+
use spin_core::{async_trait, Engine, Instance, InstancePre, Store};
8+
use spin_trigger::{TriggerAppEngine, TriggerExecutor};
89

910
wasmtime::component::bindgen!({
1011
path: ".",
@@ -62,6 +63,10 @@ impl TriggerExecutor for TimerTrigger {
6263

6364
type RunConfig = CliArgs;
6465

66+
type InstancePre = InstancePre<RuntimeData>;
67+
68+
type Instance = Instance;
69+
6570
async fn new(engine: spin_trigger::TriggerAppEngine<Self>) -> anyhow::Result<Self> {
6671
let speedup = engine
6772
.app()
@@ -113,15 +118,30 @@ impl TriggerExecutor for TimerTrigger {
113118
}
114119
Ok(())
115120
}
121+
122+
async fn instantiate_pre(
123+
engine: &Engine<RuntimeData>,
124+
component: &AppComponent,
125+
_config: &TimerTriggerConfig,
126+
) -> anyhow::Result<InstancePre<RuntimeData>> {
127+
let comp = component.load_component(engine).await?;
128+
Ok(engine
129+
.instantiate_pre(&comp)
130+
.with_context(|| format!("Failed to instantiate component '{}'", component.id()))?)
131+
}
132+
133+
async fn instantiate(
134+
store: &mut Store<RuntimeData>,
135+
pre: &Self::InstancePre,
136+
) -> anyhow::Result<Instance> {
137+
pre.instantiate_async(store).await
138+
}
116139
}
117140

118141
impl TimerTrigger {
119142
async fn handle_timer_event(&self, component_id: &str) -> anyhow::Result<()> {
120143
// Load the guest...
121144
let (instance, mut store) = self.engine.prepare_instance(component_id).await?;
122-
let EitherInstance::Component(instance) = instance else {
123-
unreachable!()
124-
};
125145
let instance = SpinTimer::new(&mut store, &instance)?;
126146
// ...and call the entry point
127147
instance.call_handle_timer_request(&mut store).await

0 commit comments

Comments
 (0)