problem:
better control my application performance and be able to trigger an event when it is very slow
proposal
be able to pass a function as a parameter in try catch and it becomes a block of code to execute a function when this happens.
Specifically what I propose is a time alert.
that at the time that the processing of the try has taken more than that time. call that block of code asynchronously
This block of code could receive as a parameter which gives me the detail in a kind of debugger (what line of code was reading at the time it reached the limit, the variables inside the try, although this could be optional, since I find it difficult )
in the same way that, in case of making return true, it is allowed to continue with the execution of the code.
An example of how I imagine this functionality would be like this
try 5000?timeAlert{
await verySlowPetition()
} timeAlert(time) {
console.log("slow app alert. alert timming is " +time)
return true; // continue with code
} catch(error){
console.log(error);
} finally {
console.log("final")
}
other advantages. this functionality could have a more advanced use of try catch that could trigger events according to the status of the scope
example
let cliente_pets;
try (cliente_pets>4)? manyPets {
cliente_pets = 1;
await verySlowPetition();
cliente_pets = 5;
neverEjecutedFunction();
} manyPets {
console.log("this client has many pets")
return false; // go to final
} catch(error){
console.log(error);
} finally {
console.log("final")
}
and it occurs to me that many functions could be introduced like
try 5000?timeAlert, (cliente_pets>4)? manyPets, (idCliente) ? isNewCliente {
cliente_pets = 1;
await verySlowPetition();
idCliente = object.idClient
cliente_pets = 5;
neverEjecutedFunction();
} manyPets {
console.log("this client has many pets")
return false; // go to final
} isNewCliente{
console.log("this client is new")
return true; // continue reading the code where it left off. as if an await had been invoked
} timeAlert(time) {
console.log("slow app alert. alert timming is " +time)
return true; // continue with code
} catch(error){
console.log(error);
} finally {
console.log("final")
}
from within these pseudo catches, the catch error could also be called
try (cliente_pets>4) ? manyPets {
manyPets = 5; // send me to pseudo catch
.....
} manyPets { // my pseudo catch
myObject.noDefinedSubAttributte.generateError = 1; // this generate, error sendme to catch
return false; // never read
} catch(error){
console.log(error);
} finally {
console.log("final")
}
I would call them pseudo catchs.
I think this functionality would make the code more readable, more understandable (there would be no need to create so many functions) and it would make it easier to create, order and improve events. at the same time that it allows to have a better control of the quality of this.