My node code starts the running of an async function inside the routes.js file.
This is an absolutely critical function, but what happens when a user closes the tab of my application? When a user closes the session, i would like to be able to stop the execution of the async function.
I search in the github forums but i found this is not possible.
The closest i managed to find is this post: How can I abort an async-await function after a certain time?
But the abortion of the function happens after a certain time here, and not wether or not the user has closed my page. So is it possible to do something similar for my programming need?
EDIT: The structure of my code is this:
//resource_file.js
module.exports = async function doStuff(arg) {
....
}
//--------------------------------------------------------------------
//routes.js
let funker = require('./resource_file.js');
module.exports = function(app) {
app.post('/pst', function(req, res) {
var arg = req.body.convo;
funker(arg).then(result => {
res.render('index.ejs');
}).catch(err => {
console.log(err);
res.render('index.ejs');
})
});
....
}