Hi I have this function that I have written.
GetIndex method
getIndex(req: connreq){
var found = false;
var number =0;
this.firereq.child(req.recipient).once('value', function(snapshot) {
if (!snapshot.exists()) {
console.log('Not exists');
this.x = '0';
}
});
}
And I call it, in this function.
SendCommand method
async sendcommand(req: connreq, cmd: string) {
this.getIndex(req);
var promise = new Promise((resolve, reject) => {
this.firereq
.child(req.recipient)
.child(this.x) .set({
sender: req.sender,
Command: cmd,
})
.then(() => {
resolve({ success: true });
})
.catch(err => {
resolve(err);
});
});
return promise;
}
However it seems that the second function continues before the getIndex method has completed. I assume we can use awaits and promises to force the sendcommand function to wait for the Getindex to finish before proceeding to the rest of it's tasks. Any assistance would be appreciated
sendcommandis promisified, you can also promisifygetIndex.