Hello,
I’m not sure if this is the correct category to post my question. I’m having this Node background transaction
nr.startBackgroundTransaction('9:9', async () => {
const transaction = nr.getTransaction();
const message = '================test================';
await SocketService.updateFriendQueues(message, (data) => {
console.log(data);
transaction.end();
});
});
And here’s the sample updateFriendQueues function
static async updateFriendQueues(message, callback) {
setTimeout(() => {
console.log(message);
callback('test');
}, 10000);
}
And it already prints the log after 10 seconds but in the transactions section I find that this transaction took 2.12 ms only though the transaction ends after 10 seconds. Is there any thing wrong with my sample code? What’s the issue here?
I also tried this
nr.startBackgroundTransaction('5:5', async () => {
const transaction = nr.getTransaction();
const message = '=============test===============';
await SocketService.updateFriendQueues(message, transaction);
});
static async updateFriendQueues(message, transaction) {
setTimeout(() => {
console.log(message);
transaction.end();
}, 10000);
}
But that didn’t work too and time is still not correct.
When I tried without async/await it worked fine and timing is correct
nr.startBackgroundTransaction('2:2', () => {
const transaction = nr.getTransaction();
setTimeout(() => {
console.log('test test test');
transaction.end();
}, 10000);
});
So why it’s not correct while using async/await and how to fix this? Thanks in advance for your help