speedster01
speedster01

Reputation: 433

Firebase Cloud Function: Generate snapshot after specified interval

I am writing a cloud function that triggers the onWrite event in the real-time database. However, I want to hold the execution of the function for a few seconds and then check the values of a few variables. However, the snapshot that I would receive would be at the instant the function starts to run right? Is there any way I can ask the system to wait once it's triggered, and then after 3 seconds(say) get the data values from my database and process them as required? Or is there anyway I can regenerate a fresh snapshot after 3 seconds and use it?

Upvotes: 0

Views: 241

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598668

The snapshot that is passed into your function contains the value as it existed when the function was triggered.

If you want to get the current value after a few seconds, you can load it:

snapshot.ref.once("value").then((newSnapshot) => {
  ... in here you can check newSnapshot.val()
})

Upvotes: 1

Related Questions