Skip to content

Commit

Permalink
Fix build of spin-timer example
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Crichton <alex@alexcrichton.com>
  • Loading branch information
alexcrichton committed Mar 15, 2024
1 parent bd34327 commit 3613467
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions examples/spin-timer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::collections::HashMap;

use anyhow::Context;
use clap::Args;
use serde::{Deserialize, Serialize};
use spin_app::MetadataKey;
use spin_core::async_trait;
use spin_trigger::{EitherInstance, TriggerAppEngine, TriggerExecutor};
use spin_app::{AppComponent, MetadataKey};
use spin_core::{async_trait, Engine, Instance, InstancePre, Store};
use spin_trigger::{TriggerAppEngine, TriggerExecutor};

wasmtime::component::bindgen!({
path: ".",
Expand Down Expand Up @@ -62,6 +63,10 @@ impl TriggerExecutor for TimerTrigger {

type RunConfig = CliArgs;

type InstancePre = InstancePre<RuntimeData>;

type Instance = Instance;

async fn new(engine: spin_trigger::TriggerAppEngine<Self>) -> anyhow::Result<Self> {
let speedup = engine
.app()
Expand Down Expand Up @@ -113,15 +118,30 @@ impl TriggerExecutor for TimerTrigger {
}
Ok(())
}

async fn instantiate_pre(
engine: &Engine<RuntimeData>,
component: &AppComponent,
_config: &TimerTriggerConfig,
) -> anyhow::Result<InstancePre<RuntimeData>> {
let comp = component.load_component(engine).await?;
Ok(engine
.instantiate_pre(&comp)
.with_context(|| format!("Failed to instantiate component '{}'", component.id()))?)
}

async fn instantiate(
store: &mut Store<RuntimeData>,
pre: &Self::InstancePre,
) -> anyhow::Result<Instance> {
pre.instantiate_async(store).await
}
}

impl TimerTrigger {
async fn handle_timer_event(&self, component_id: &str) -> anyhow::Result<()> {
// Load the guest...
let (instance, mut store) = self.engine.prepare_instance(component_id).await?;
let EitherInstance::Component(instance) = instance else {
unreachable!()
};
let instance = SpinTimer::new(&mut store, &instance)?;
// ...and call the entry point
instance.call_handle_timer_request(&mut store).await
Expand Down

0 comments on commit 3613467

Please sign in to comment.