mirror of
				https://github.com/xfarrow/blink
				synced 2025-06-27 09:03:02 +02:00 
			
		
		
		
	Update
This commit is contained in:
		| @@ -34,7 +34,7 @@ function entryPoint(){ | |||||||
|     valore, in questo caso console.log("I started here!"); |     valore, in questo caso console.log("I started here!"); | ||||||
| 
 | 
 | ||||||
|     Questo però è solo un esempio in quanto le istruzioni verranno |     Questo però è solo un esempio in quanto le istruzioni verranno | ||||||
|     eseguite in maniera sincrona (non concorrenti), ma che ci permette di |     eseguite in maniera sincrona, ma che ci permette di | ||||||
|     comprendere le basi di questo meccanismo. |     comprendere le basi di questo meccanismo. | ||||||
|     */ |     */ | ||||||
|      |      | ||||||
| @@ -26,6 +26,25 @@ async function f2() { | |||||||
|    |    | ||||||
|   f2(); |   f2(); | ||||||
| 
 | 
 | ||||||
|  |   // Tutto il codice nella stessa funzione (o nello stesso blocco di codice)
 | ||||||
|  |   // dopo "await" è da considerarsi nel "then()" di una promessa. Pertanto dopo
 | ||||||
|  |   // await, il flusso di esecuzione va fuori al blocco di codide. Ad esempio considera
 | ||||||
|  |   // il seguente esempio:
 | ||||||
|  |   async function exampleAsyncFunction() { | ||||||
|  |     console.log('Before await'); | ||||||
|  |     await new Promise(function(resolve, reject) { | ||||||
|  |         setTimeout(() => resolve("done"), 500); | ||||||
|  |       }); // Pauses execution here until the promise resolves.
 | ||||||
|  |     console.log('After await'); | ||||||
|  |   } | ||||||
|  |    | ||||||
|  |   console.log('Start'); | ||||||
|  |   exampleAsyncFunction(); | ||||||
|  |   console.log('End'); | ||||||
|  | 
 | ||||||
|  |   // Il risultato sarà:
 | ||||||
|  |   // Start, Before Await, End, After await
 | ||||||
|  | 
 | ||||||
|   // Domande
 |   // Domande
 | ||||||
|   // 
 |   // 
 | ||||||
|   // Why await only works in async function in javascript?
 |   // Why await only works in async function in javascript?
 | ||||||
| @@ -37,3 +56,6 @@ async function f2() { | |||||||
|   // Si faccia presente che non è possibile creare da zero una funzione asincrona (come
 |   // Si faccia presente che non è possibile creare da zero una funzione asincrona (come
 | ||||||
|   // setInterval o fetch)
 |   // setInterval o fetch)
 | ||||||
|   // https://stackoverflow.com/questions/61857274/how-to-create-custom-asynchronous-function-in-javascript
 |   // https://stackoverflow.com/questions/61857274/how-to-create-custom-asynchronous-function-in-javascript
 | ||||||
|  |   //
 | ||||||
|  |   // Altra domanda interessante
 | ||||||
|  |   // https://stackoverflow.com/questions/42624647/why-use-async-when-i-have-to-use-await
 | ||||||
| @@ -1,11 +0,0 @@ | |||||||
| async function exampleAsyncFunction() { |  | ||||||
|     console.log('Before await'); |  | ||||||
|     await new Promise(function(resolve, reject) { |  | ||||||
|         setTimeout(() => resolve("done"), 500); |  | ||||||
|       }); // Pauses execution here until the promise resolves. |  | ||||||
|     console.log('After await'); |  | ||||||
|   } |  | ||||||
|    |  | ||||||
|   console.log('Start'); |  | ||||||
|   exampleAsyncFunction(); |  | ||||||
|   console.log('End'); |  | ||||||
							
								
								
									
										31
									
								
								backend/tutorials/sincrono_vs_asincrono.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								backend/tutorials/sincrono_vs_asincrono.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,31 @@ | |||||||
|  | Link utili: | ||||||
|  | https://stackoverflow.com/questions/748175/asynchronous-vs-synchronous-execution-what-is-the-difference | ||||||
|  | https://stackoverflow.com/questions/7131991/asynchronous-and-synchronous-terms | ||||||
|  |  | ||||||
|  | La parola "sincrono" in contesto informatico vuol dire "sincronizzato", ovvero | ||||||
|  | il chiamante deve aspettare la risposta del chiamato, mentre | ||||||
|  | "async" vuol dire "non sincronizzato".  | ||||||
|  | Ciò vuol dire (non)/sincronizzato con altre porzioni di codice. | ||||||
|  | La definizione da dizionario invece differisce.  | ||||||
|  | Per Treccani: "Sincrono: Che avviene nello stesso momento", | ||||||
|  | mentre sappiamo che un'operazione sincrona rispetto ad un'altra | ||||||
|  | non avviene allo stesso tempo. | ||||||
|  | In informatica dire "un metodo è (a)sincrono" deve | ||||||
|  | sempre accompagnate da "rispetto a chi" è (a)sincrono. | ||||||
|  |  | ||||||
|  | Possiamo anche pensarla così: (https://stackoverflow.com/a/32052611/18371893) | ||||||
|  |  | ||||||
|  | In a nutshell, synchronization refers to two or more processes' start and end points, NOT their executions.  | ||||||
|  | In this example, Process A's endpoint is synchronized with Process B's start point: | ||||||
|  |  | ||||||
|  | SYNCHRONOUS | ||||||
|  |    |--------A--------| | ||||||
|  |                      |--------B--------| | ||||||
|  |  | ||||||
|  | Asynchronous processes, on the other hand, do not have their start and endpoints synchronized: | ||||||
|  |  | ||||||
|  | ASYNCHRONOUS | ||||||
|  |    |--------A--------| | ||||||
|  |          |--------B--------| | ||||||
|  |  | ||||||
|  | Where Process A overlaps Process B, they're running concurrently or synchronously (dictionary definition), hence the confusion.  | ||||||
		Reference in New Issue
	
	Block a user