Reputation: 914
I'm using Firebase Functions to do additional updates of the Realtime Database after some event has occured (created / updated / deleted of a record inside database) and that triggers another event. Is there a way to prevent the second event? I know I can cancel it if conditions are met, but I would like to prevent it from starting the second time.
Upvotes: 2
Views: 1340
Reputation: 598623
There is no way to prevent an event from within the code that triggers it. That would allow for all kinds of loopholes that nobody wants.
You can change your trigger to not respond anymore to the change. For example, you'll often see that functions only need to respond to creation of nodes and not to updates. In that case you'd tie a trigger to onCreate
and not to onUpdate
or onWrite
.
Alternatively you can catch the update in the function itself and bypass further updates. For example, if you have a function that modifies data, you can detect that it has already modified the data by having a flag property in the data, or by detecting that there are no changes the second time around. You'd skip re-updating in that case.
Note that the second approach can catch more cases, but results in one more trigger than strictly needed. So I'd always prefer the first approach if possible.
Upvotes: 3