Skip to content

Caching data between invocations #397

Answered by softprops
rimutaka asked this question in Q&A
Discussion options

You must be logged in to vote

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 implements Handler so I believe you can just have a type with state that lives across invocations of a lambda task that implements Handler

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(

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by calavera
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #372 on January 10, 2022 22:42.