A FlowBoost user asked how to add multiple event registrants in a single webhook call, specifically for the case where there’s a VIP plus a certain # of guests.
It’s easy using JavaScript’s built-in async features, and it doesn’t take any more time than a single FBCounter update!
If your basic call is like this:
let counterName = `/eventCounters/v1/{{Program.Id}}`;
FBCounter.autoAdd(counterName)
.then(newEntry => newEntry.entryIndex)
.then(success)
.catch(failure);
Then expand that to call FBCounter.autoAdd
multiple times:
let counterName = `/eventCounters/v1/{{Program.Id}}`,
numberToAdd = 3;
Promise.all(
Array(numberToAdd)
.fill(counterName)
.map(FBCounter.autoAdd)
)
.then(newEntries =>
Math.max(...newEntries.map(newEntry => newEntry.entryIndex))
)
.then(success)
.catch(failure);
Only real trick in there is returning the maximum entryIndex
value among all the parallel updates. Remember, the seemingly “last” one in the array doesn’t necessarily finish last, by definition.
So you wait for them all to complete (as Promise.all
always does) and then run Math.max
over all of ’em to get the highest index. That’s your final count.
FBCounter v2 will make this easier
On the 2024 roadmap is FBCounter v2, which will be a kajillion times faster thanks to a different backend db and will offer easier plus-something/minus-something methods.