-
It is possible to initialize a resource in The downside of this method is that the initialization must be done upfront and the resource cannot be updated. I've been trying to implement a cache that can be updated from inside the handler, but no matter what I tried it's a breaking change. Does anyone know a way of updating a shared resource from inside the handler fn without breaking the current handler_fn interface? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
hander_fn is a factory method for creating an instance of a type which implements a generic Handler trait. The example pseudo code struct Counter {
data: usize
}
impl Default for Counter {
fn default() -> Self {
Counter { data: 0 }
}
}
impl Handler<A, B> for Counter {
type Error = YourErrType;
type Fut = YourFutType;
fn call(&mut self, req: A, ctx: Context) -> Self::Fut {
// update your state
self.data += 1;
// do the thing that returns Self::Fut
}
}
fn main() {
lambda_runtime::run(Counter::default()).await?;
Ok(())
} |
Beta Was this translation helpful? Give feedback.
hander_fn is a factory method for creating an instance of a type which implements a generic Handler trait.
The
run
function accepts any type which implementsHandler
so I believe you can just have a type with state that lives across invocations of a lambda task that implementsHandler
example pseudo code