mirror of
https://github.com/xfarrow/blink
synced 2025-06-27 09:03:02 +02:00
npx eslint --fix
This commit is contained in:
@ -1,35 +1,32 @@
|
||||
// https://javascript.info/callbacks
|
||||
|
||||
function execute_action(param, callback){
|
||||
|
||||
if(param == "something"){
|
||||
console.log("Executing action: " + param);
|
||||
callback(null, Date.now());
|
||||
}
|
||||
else{
|
||||
// We can call callback with one argument even if
|
||||
// the signature states two parameters
|
||||
callback(new Error("Invalid parameter"))
|
||||
}
|
||||
function execute_action (param, callback) {
|
||||
if (param == 'something') {
|
||||
console.log('Executing action: ' + param);
|
||||
callback(null, Date.now());
|
||||
} else {
|
||||
// We can call callback with one argument even if
|
||||
// the signature states two parameters
|
||||
callback(new Error('Invalid parameter'));
|
||||
}
|
||||
}
|
||||
|
||||
function entryPoint(){
|
||||
/* ===== Begin Simple callback ===== */
|
||||
function entryPoint () {
|
||||
/* ===== Begin Simple callback ===== */
|
||||
|
||||
execute_action("something", function (error, time_of_completion){
|
||||
if(error){
|
||||
console.log("Something happened");
|
||||
}
|
||||
else{
|
||||
console.log("Time of completion: " + new Date(time_of_completion).toDateString());
|
||||
}
|
||||
});
|
||||
console.log("I started here!");
|
||||
/*
|
||||
Ciò è utile se ad esempio execute_action fa operazioni lente (ad esempio
|
||||
execute_action('something', function (error, time_of_completion) {
|
||||
if (error) {
|
||||
console.log('Something happened');
|
||||
} else {
|
||||
console.log('Time of completion: ' + new Date(time_of_completion).toDateString());
|
||||
}
|
||||
});
|
||||
console.log('I started here!');
|
||||
/*
|
||||
Ciò è utile se ad esempio execute_action fa operazioni lente (ad esempio
|
||||
scrittura su database, connessioni HTTP ecc..) ma abbiamo bisogno
|
||||
del suo valore di ritorno per continuare una determinata operazione
|
||||
(in questo caso la data di completamento dell'esecuzione),
|
||||
(in questo caso la data di completamento dell'esecuzione),
|
||||
senza però bloccare le altre operazioni che non hanno bisogno di tale
|
||||
valore, in questo caso console.log("I started here!");
|
||||
|
||||
@ -37,12 +34,12 @@ function entryPoint(){
|
||||
eseguite in maniera sincrona, ma che ci permette di
|
||||
comprendere le basi di questo meccanismo.
|
||||
*/
|
||||
|
||||
/* ===== End Simple Callback ===== */
|
||||
|
||||
/* ===== End Simple Callback ===== */
|
||||
}
|
||||
|
||||
entryPoint();
|
||||
|
||||
// callbacks usually indicate that the
|
||||
// execution of their code will continue
|
||||
// asynchronously.
|
||||
// asynchronously.
|
||||
|
Reference in New Issue
Block a user